— Scott McNealy, Sun Microsystems Chairman, President and ceo


before you look at the next page



Download 40,57 Mb.
Pdf ko'rish
bet212/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   208   209   210   211   212   213   214   215   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

before you look at the next page where we 
begin to reveal 
everything.
(thus rendering the whole exercise completely useless, robbing 
you of your One Big Chance to burn some brain calories) 
modifying a 
class tree
brain
power
A


interfaces and 
polymorphism
you are here
4
219
On the next few pages, we’re going to walk through 
some possibilities. We’re not yet worried about 
whether Java can actually do what we come up with. 
We’ll cross that bridge once we have a good idea of 
some of the tradeoffs.
Let’s explore some design options 
for reusing some of our existing 
classes in a PetShop program.
We take the easy path, and put pet 
methods in class Animal. 
1
Option one
All the Animals will instantly inherit 
the pet behaviors. We won’t have to 
touch the existing Animal subclasses 
at all, and any Animal subclasses 
created in the future will also get to 
take advantage of inheriting those
methods. That way, class Animal can 
be used as the polymorphic type in 
any program that wants to treat the 
Animals as pets
Pros:
So... when was the last time you 
saw a Hippo at a pet shop? Lion? 
Wolf? Could be dangerous to give 
non-pets pet methods. 
Also, we almost certainly WILL 
have to touch the pet classes 
like Dog and Cat, because (in 
our house, anyway) Dogs 
and Cats tend to imple-
ment pet behaviors 
VERY differently.
Cons:
Tiger
Animal
Canine
Hippo
Dog
Wolf
Cat
Lion
Feline
put all the pet 
method code up here 
for inheritance.



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   208   209   210   211   212   213   214   215   ...   555




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