— Scott McNealy, Sun Microsystems Chairman, President and ceo


will always pick the right one



Download 40,57 Mb.
Pdf ko'rish
bet170/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   166   167   168   169   170   171   172   173   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

will always pick the right one. And 
the right one means, the most specific 
version for that particular object.
Sharpen your pencil


inheritance and 
polymorphism
you are here
4
177
Using IS-A and HAS-A
Remember that when one class 
inherits from another, we say that the 
subclass extends the superclass. When 
you want to know if one thing should 
extend another, apply the IS-A test. 
Triangle IS-A Shape, yeah, that works.
Cat IS-A Feline, that works too.
Surgeon IS-A Doctor, still good.
Tub extends Bathroom, sounds 
reasonable. 
Until you apply the IS-A test. 
To know if you’ve designed your types 
correctly, ask, “Does it make sense to 
say type X IS-A type Y?” If it doesn’t, 
you know there’s something wrong 
with the design, so if we apply the IS -A 
test, Tub IS-A Bathroom is defi nitely 
false. 
What if we reverse it to Bathroom 
extends Tub? That still doesn’t work, 
Bathroom IS-A Tub doesn’t work.
Tub and Bathroom are related, but 
not through inheritance. Tub and 
Bathroom are joined by a HAS-A 
relationship. Does it make sense to 
say “Bathroom HAS-A Tub”? If yes, 
then it means that Bathroom has a 
Tub instance variable. In other words, 
Bathroom has a reference to a Tub, but 
Bathroom does not extend Tub and 
vice-versa.
Does it make sense to 
say a Tub IS-A Bathroom? Or a 
Bathroom IS-A Tub? Well it doesn’t to 
me. The relationship between my Tub 
and my Bathroom is HAS-A. Bathroom 
HAS-A Tub. That means Bathroom 
h a s a Tub instance variable. 
Bathroom
Tub bathtub;
Sink theSink;

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   166   167   168   169   170   171   172   173   ...   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