Commit 814dd480 authored by Zed's avatar Zed

The beginning of inheritance.

parent 687219d1
from oop import *
import Fruit
IS_A = Fruit
def _init(self, color):
Fruit._init(self, 'apple', color)
_set = Fruit._set
_get = Fruit._get
_get_kind = Fruit._get_kind
_set_kind = Fruit._set_kind
eat = Fruit.eat
throw = Fruit.throw
......@@ -22,3 +22,11 @@ class Car:
print(f"{who} will drive a {color} {kind} to {where}")
class Buick(Car):
def __init__(self, color):
super().__init__('buick', color)
def park(self, where):
print(f"You are parking your buick in {where}.")
......@@ -23,3 +23,5 @@ def eat(self):
def throw(self, at_who):
print(f"Throwing a {get(self, 'kind')} at {at_who}.")
......@@ -4,6 +4,7 @@ from pprint import pprint
import Car
import Fruit
import Apple
def test_new():
a = new(Fruit, "apple", "red")
......@@ -42,16 +43,17 @@ def test_obj_methods():
c.drive("Zed", "Texas")
def test_inheritance():
a = new(Apple, 'red')
assert get(a, 'fresh') == True
assert get(a, 'kind') == 'apple'
assert get(a, 'color') == 'red'
set(a, 'color', 'green')
assert get(a, 'color') == 'green'
Apple.eat(a)
assert get(a, 'fresh') == False
Apple.throw(a, 'Zed')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment