Author Dusty Phillips Reviewers


What payment type? (purchase, rental) purchase



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

What payment type? (purchase, rental) purchase
Enter the square feet: 800
Enter number of bedrooms: 3
Enter number of baths: 2
What laundry facilities does the property have? (coin, ensuite,
one) ensuite
Does the property have a balcony? (yes, no, solarium) yes
What is the selling price? $200,000
What are the estimated taxes? 1500
>>> agent.display_properties()
PROPERTY DETAILS
================
square footage: 900
bedrooms: 2
bathrooms: one and a half
HOUSE DETAILS
# of stories: 1
garage: detached
fenced yard: yes
RENTAL DETAILS
rent: 1200
estimated utilities: included
furnished: no
PROPERTY DETAILS
================
square footage: 800
bedrooms: 3
www.it-ebooks.info


Chapter 3
[
 95 
]
bathrooms: 2
APARTMENT DETAILS
laundry: ensuite
has balcony: yes
PURCHASE DETAILS
selling price: $200,000
estimated taxes: 1500
Exercises
Look around you at some of the physical objects in your workspace and see if you 
can describe them in an inheritance hierarchy. Humans have been dividing the 
world into taxonomies like this for centuries, so it shouldn't be difficult. Are there 
any non-obvious inheritance relationships between classes of objects? If you were to 
model these objects in a computer application, what properties and methods would 
they share? Which ones would have to be polymorphically overridden? 
What properties would be completely different between them?
Now, write some code. No, not for the physical hierarchy; that's boring. Physical 
items have more properties than methods. Just think about a pet programming 
project you've wanted to tackle in the past year, but never got around to. For 
whatever problem you want to solve, try to think of some basic inheritance 
relationships. Then implement them. Make sure that you also pay attention to the 
sorts of relationships that you actually don't need to use inheritance for. Are there 
any places where you might want to use multiple inheritance? Are you sure? Can 
you see any place you would want to use a mixin? Try to knock together a quick 
prototype. It doesn't have to be useful or even partially working. You've seen how 
you can test code using 
python -i
already; just write some code and test it in the 
interactive interpreter. If it works, write some more. If it doesn't, fix it!
Now, take a look at the real estate example. This turned out to be quite an effective use 
of multiple inheritance. I have to admit though, I had my doubts when I started the 
design. Have a look at the original problem and see if you can come up with another 
design to solve it that uses only single inheritance. How would you do it with abstract 
base classes? What about a design that doesn't use inheritance at all? Which do you 
think is the most elegant solution? Elegance is a primary goal in Python development, 
but each programmer has a different opinion as to what is the most elegant solution. 
Some people tend to think and understand problems most clearly using composition, 
while others find multiple inheritance to be the most useful model.
www.it-ebooks.info


When Objects Are Alike

Download 2,95 Mb.

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