Author Dusty Phillips Reviewers



Download 2,95 Mb.
Pdf ko'rish
bet88/183
Sana20.07.2022
Hajmi2,95 Mb.
#831085
1   ...   84   85   86   87   88   89   90   91   ...   183
Bog'liq
python3-oop

[
 82 
]
All this line does is get the set of methods and properties that the class has, including 
any parent classes in its class hierarchy:
if set(cls.__abstractmethods__) <= attrs:
This line uses set notation to see whether the set of abstract methods in this class 
have been supplied in the candidate class. Note that it doesn't check to see whether 
the methods have been implemented, just if they are there. Thus, it's possible for a 
class to be a subclass and yet still be an abstract class itself.
return True
If all the abstract methods have been supplied, then the candidate class is a subclass 
of this class and we return 
True
. The method can legally return one of the three 
values: 
True

False
, or 
NotImplemented

True
and 
False
indicate that the class is
or is not definitively a subclass of this class:
return NotImplemented
If any of the conditionals have not been met (that is, the class is not 
MediaLoader
or not all abstract methods have been supplied), then return 
NotImplemented
. This 
tells the Python machinery to use the default mechanism (does the candidate class 
explicitly extend this class?) for subclass detection.
In short, we can now define the 
Ogg
class as a subclass of the 
MediaLoader
class 
without actually extending the 
MediaLoader
class:
>>> class Ogg():
... ext = '.ogg'
... def play(self):
... print("this will play an ogg file")
...
>>> issubclass(Ogg, MediaLoader)
True
>>> isinstance(Ogg(), MediaLoader)
True
Case study
Let's try to tie everything we've learned together with a larger example. We'll be 
designing a simple real estate application that allows an agent to manage properties 
available for purchase or rent. There will be two types of properties: apartments and 
houses. The agent needs to be able to enter a few relevant details about new properties, 
list all currently available properties, and mark a property as sold or rented. For 
brevity, we won't worry about editing property details or reactivating a property
after it is sold.
www.it-ebooks.info


Chapter 3

Download 2,95 Mb.

Do'stlaringiz bilan baham:
1   ...   84   85   86   87   88   89   90   91   ...   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