Author Dusty Phillips Reviewers


Different sets of arguments



Download 2,95 Mb.
Pdf ko'rish
bet78/183
Sana20.07.2022
Hajmi2,95 Mb.
#831085
1   ...   74   75   76   77   78   79   80   81   ...   183
Bog'liq
python3-oop

Different sets of arguments
This is going to make things complicated as we return to our 
Friend
multiple 
inheritance example. In the 
__init__
method for 
Friend
, we were originally
calling 
__init__
for both parent classes, 
with different sets of arguments
:
Contact.__init__(self, name, email)
AddressHolder.__init__(self, street, city, state, code)
How can we manage different sets of arguments when using 
super
? We don't 
necessarily know which class 
super
is going to try to initialize first. Even if we 
did, we need a way to pass the "extra" arguments so that subsequent calls to
super
, on other subclasses, receive the right arguments.
Specifically, if the first call to 
super
passes the 
name
and 
email
arguments 
to 
Contact.__init__
, and 
Contact.__init__
then calls 
super
, it needs to 
be able to pass the address-related arguments to the "next" method, which is 
AddressHolder.__init__
.
This is a problem whenever we want to call superclass methods with the same
name, but with different sets of arguments. Most often, the only time you
would want to call a superclass with a completely different set of arguments is
in 
__init__
, as we're doing here. Even with regular methods, though, we may want 
to add optional parameters that only make sense to one subclass or set of subclasses.
Sadly, the only way to solve this problem is to plan for it from the beginning. We 
have to design our base class parameter lists to accept keyword arguments for any 
parameters that are not required by every subclass implementation. Finally, we must 
ensure the method freely accepts unexpected arguments and passes them on to its 
super
call, in case they are necessary to later methods in the inheritance order.
www.it-ebooks.info


Chapter 3

Download 2,95 Mb.

Do'stlaringiz bilan baham:
1   ...   74   75   76   77   78   79   80   81   ...   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