[Python #11] create e44.py

This commit is contained in:
kjg 2020-06-17 22:48:58 +09:00
parent 7a87bdc8e6
commit 3c7bc7cd1a
6 changed files with 116 additions and 0 deletions

View file

@ -0,0 +1,13 @@
class Parent(object):
def implicit(self):
print("PARENT implicit()")
class Child(Parent):
pass
dad = Parent()
son = Child()
dad.implicit()
son.implicit()

View file

@ -0,0 +1,14 @@
class Parent(object):
def override(self):
print("PARENT override()")
class Child(Parent):
def override(self):
print("CHILD override()")
dad = Parent()
son = Child()
dad.override()
son.override()

View file

@ -0,0 +1,16 @@
class Parent(object):
def altered(self):
print("PARENT altered()")
class Child(Parent):
def altered(self):
print("CHILD, BEFORE PARENT altered()")
super(Child, self).altered()
print("CHILD, AFTER PARENT altered()")
dad = Parent()
son = Child()
dad.altered()
son.altered()

View file

@ -0,0 +1,34 @@
class Parent(object):
def override(self):
print("PARENT override()")
def implicit(self):
print("PARENT implicit()")
def altered(self):
print("PARENT altered()")
class Child(Parent):
def override(self):
print("CHILD, override()")
def altered(self):
print("CHILD, BERFORE altered()")
super(Child, self).altered()
print("CHILD, AFTER PARENT altered()")
dad = Parent()
son = Child()
dad.implicit()
son.implicit()
dad.override()
son.override()
dad.altered()
son.altered()

View file

@ -0,0 +1,32 @@
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):
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()
son.override()
son.altered()

View file

@ -147,5 +147,12 @@ How to use dictionary
How to use class How to use class
**** ex41 **** ex41
practice class practice class
*** Python #9
**** ex42 **** ex42
review class and object review class and object
*** Python #10
**** ex43
Analysis and Design object
*** Python #11
**** ex44
difference with inheritance and compositon