-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlearn44.py
56 lines (41 loc) · 1.1 KB
/
learn44.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
# Composition
class Other(object):
def override(self):
print("OTHER override()")
def implicit(self):
print("OTHER implicit()")
def altered(self):
print("OTHER altered()")
class Child(object):
def __init__(self): # This allows for it to be possible to get the Other stuff? Even though it is its own Class
self.other = Other()
def implicit(self):
self.other.implicit()
def override(self):
print("CHILD override()")
def altered(self):
print("CHILD BEFORE OTHER altered()")
self.other.altered()
print("CHILD AFTER OTHER altered()")
son = Child()
son.implicit()
print("-----")
son.override()
print("-----")
son.altered()
"""
# Inhertance
class Parent(object):
def altered(self):
print("PARENT altered…")
class Child(Parent):
def altered(self):
print("CHILD BEFORE PARENT altered.")
super(Child, self).altered() # This prints 'Parent altered'
print("CHILD AFTER PARENT altered…")
dad = Parent()
son = Child()
dad.altered()
print("---------------------")
son.altered()
"""