ch11-24: clean up by @eumiro & sync with Atlas
This commit is contained in:
4
14-inheritance/README.rst
Normal file
4
14-inheritance/README.rst
Normal file
@@ -0,0 +1,4 @@
|
||||
Sample code for Chapter 14 - "Inheritance: for good or for worse"
|
||||
|
||||
From the book "Fluent Python, Second Edition" by Luciano Ramalho (O'Reilly, 2021)
|
||||
https://learning.oreilly.com/library/view/fluent-python-2nd/9781492056348/
|
||||
27
14-inheritance/diamond.py
Normal file
27
14-inheritance/diamond.py
Normal file
@@ -0,0 +1,27 @@
|
||||
class A:
|
||||
def ping(self):
|
||||
print('ping:', self)
|
||||
|
||||
|
||||
class B(A):
|
||||
def pong(self):
|
||||
print('pong:', self)
|
||||
|
||||
|
||||
class C(A):
|
||||
def pong(self):
|
||||
print('PONG:', self)
|
||||
|
||||
|
||||
class D(B, C):
|
||||
|
||||
def ping(self):
|
||||
super().ping()
|
||||
print('post-ping:', self)
|
||||
|
||||
def pingpong(self):
|
||||
self.ping()
|
||||
super().ping()
|
||||
self.pong()
|
||||
super().pong()
|
||||
C.pong(self)
|
||||
Reference in New Issue
Block a user