From 3c7bc7cd1adacddfe295f16b2bc2a9923f503d43 Mon Sep 17 00:00:00 2001 From: kjg Date: Wed, 17 Jun 2020 22:48:58 +0900 Subject: [PATCH] [Python #11] create e44.py --- kjg/python-the-hard-way/e44a.py | 13 +++++++++++++ kjg/python-the-hard-way/e44b.py | 14 ++++++++++++++ kjg/python-the-hard-way/e44c.py | 16 ++++++++++++++++ kjg/python-the-hard-way/e44d.py | 34 +++++++++++++++++++++++++++++++++ kjg/python-the-hard-way/e44e.py | 32 +++++++++++++++++++++++++++++++ kjg/python.org | 7 +++++++ 6 files changed, 116 insertions(+) create mode 100644 kjg/python-the-hard-way/e44a.py create mode 100644 kjg/python-the-hard-way/e44b.py create mode 100644 kjg/python-the-hard-way/e44c.py create mode 100644 kjg/python-the-hard-way/e44d.py create mode 100644 kjg/python-the-hard-way/e44e.py diff --git a/kjg/python-the-hard-way/e44a.py b/kjg/python-the-hard-way/e44a.py new file mode 100644 index 0000000..211745e --- /dev/null +++ b/kjg/python-the-hard-way/e44a.py @@ -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() diff --git a/kjg/python-the-hard-way/e44b.py b/kjg/python-the-hard-way/e44b.py new file mode 100644 index 0000000..0c94ffc --- /dev/null +++ b/kjg/python-the-hard-way/e44b.py @@ -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() diff --git a/kjg/python-the-hard-way/e44c.py b/kjg/python-the-hard-way/e44c.py new file mode 100644 index 0000000..9d1dbe0 --- /dev/null +++ b/kjg/python-the-hard-way/e44c.py @@ -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() diff --git a/kjg/python-the-hard-way/e44d.py b/kjg/python-the-hard-way/e44d.py new file mode 100644 index 0000000..9c93926 --- /dev/null +++ b/kjg/python-the-hard-way/e44d.py @@ -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() diff --git a/kjg/python-the-hard-way/e44e.py b/kjg/python-the-hard-way/e44e.py new file mode 100644 index 0000000..b5840cf --- /dev/null +++ b/kjg/python-the-hard-way/e44e.py @@ -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() diff --git a/kjg/python.org b/kjg/python.org index ecec546..273ecf9 100644 --- a/kjg/python.org +++ b/kjg/python.org @@ -147,5 +147,12 @@ How to use dictionary How to use class **** ex41 practice class +*** Python #9 **** ex42 review class and object +*** Python #10 +**** ex43 +Analysis and Design object +*** Python #11 +**** ex44 +difference with inheritance and compositon