-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex44.py
65 lines (49 loc) · 1.21 KB
/
ex44.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Parent(object):
def implicit(self):
print("PARENT implicit()")
def override(self):
print("PARENT override()")
def altered(self):
print("PARENT altered()")
class Child(Parent):
def __init__(self, stuff):
self.stuff = stuff
super(Child, self).__init__()
def override(self):
print("CHILD override()")
def altered(self):
print("CHILD, before PARENT altered()")
super(Child, self).altered()
print("CHILD, after PARENT altered()")
class Other(object):
def override(self):
print("OTHER override()")
def implicit(self):
print("OTHER implicit()")
def altered(self):
print("OTHER altered()")
class OtherChild(object):
def __init__(self):
self.other = Other()
def implicit(self):
self.other.implicit()
def override(self):
print("OTHER CHILD override()")
def altered(self):
print("OTHER CHILD, before OTHER altered()")
self.other.altered()
print("OTHER CHILD, after OTHER altered()")
print("*** Inheritance: ***")
dad = Parent()
son = Child("some stuff to not break on init")
otherson = OtherChild()
dad.implicit()
son.implicit()
dad.override()
son.override()
dad.altered()
son.altered()
print("\n*** Composition: ***")
otherson.implicit()
otherson.override()
otherson.altered()