Author Dusty Phillips Reviewers



Download 2,95 Mb.
Pdf ko'rish
bet75/183
Sana20.07.2022
Hajmi2,95 Mb.
#831085
1   ...   71   72   73   74   75   76   77   78   ...   183
Bog'liq
python3-oop

Method Resolution Order
) attribute on 
the class. This is beyond the scope of this book. If you think you need 
to understand it, I recommend 
Expert Python Programming

Tarek Ziadé

Packt Publishing
, or read the original documentation on the topic at 
http://www.python.org/download/releases/2.3/mro/
.
www.it-ebooks.info


Chapter 3
[
 69 
]
Let's look at a second contrived example that illustrates this problem more clearly. 
Here we have a base class that has a method named 
call_me
. Two subclasses 
override that method, and then another subclass extends both of these using multiple 
inheritance. This is called diamond inheritance because of the diamond shape of the 
class diagram:
Subclass
BaseClass
+call_me()
LeftSubclass
RightSubclass
+call_me()
+call_me()
+call_me()
Let's convert this diagram to code; this example shows when the methods are called:
class BaseClass:
num_base_calls = 0
def call_me(self):
print("Calling method on Base Class")
self.num_base_calls += 1
class LeftSubclass(BaseClass):
num_left_calls = 0
def call_me(self):
BaseClass.call_me(self)
print("Calling method on Left Subclass")
self.num_left_calls += 1
class RightSubclass(BaseClass):
num_right_calls = 0
def call_me(self):
BaseClass.call_me(self)
print("Calling method on Right Subclass")
self.num_right_calls += 1
class Subclass(LeftSubclass, RightSubclass):
www.it-ebooks.info


When Objects Are Alike
[
 70 

Download 2,95 Mb.

Do'stlaringiz bilan baham:
1   ...   71   72   73   74   75   76   77   78   ...   183




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish