Author Dusty Phillips Reviewers



Download 2,95 Mb.
Pdf ko'rish
bet99/183
Sana20.07.2022
Hajmi2,95 Mb.
#831085
1   ...   95   96   97   98   99   100   101   102   ...   183
Bog'liq
python3-oop

[
 96 
]
Finally, try adding some new features to the three designs. Whatever features strike 
your fancy are fine. I'd like to see a way to differentiate between available and 
unavailable properties, for starters. It's not of much use to me if it's already rented!
Which design is easiest to extend? Which is hardest? If somebody asked you why 
you thought this, would you be able to explain yourself?
Summary
We've gone from simple inheritance, one of the most useful tools in the object-oriented 
programmer's toolbox, all the way through to multiple inheritance, one of the most 
complicated. Inheritance can be used to add functionality to existing classes and built-
ins using inheritance. Abstracting similar code into a parent class can help increase 
maintainability. Methods on parent classes can be called using 
super
and argument 
lists must be formatted safely for these calls to work when using multiple inheritance.
In the next chapter, we'll cover the subtle art of handling exceptional circumstances.
www.it-ebooks.info


[
 97 
]
Expecting the Unexpected
Programs are very fragile. It would be ideal if code always returned a valid result
but sometimes a valid result can't be calculated. For example, it's not possible to 
divide by zero, or to access the eighth item in a five-item list.
In the old days, the only way around this was to rigorously check the inputs for every 
function to make sure they made sense. Typically, functions had special return values 
to indicate an error condition; for example, they could return a negative number to 
indicate that a positive value couldn't be calculated. Different numbers might mean 
different errors occurred. Any code that called this function would have to explicitly 
check for an error condition and act accordingly. A lot of code didn't bother to do this, 
and programs simply crashed. However, in the object-oriented world, this is not
the case.
In this chapter, we will study 
exceptions
, special error objects that only need to be 
handled when it makes sense to handle them. In particular, we will cover:
• 
How to cause an exception to occur
• 
How to recover when an exception has occurred
• 
How to handle different exception types in different ways
• 
Cleaning up when an exception has occurred
• 
Creating new types of exception
• 
Using the exception syntax for flow control
www.it-ebooks.info


Expecting the Unexpected

Download 2,95 Mb.

Do'stlaringiz bilan baham:
1   ...   95   96   97   98   99   100   101   102   ...   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