Author Dusty Phillips Reviewers



Download 2,95 Mb.
Pdf ko'rish
bet24/183
Sana20.07.2022
Hajmi2,95 Mb.
#831085
1   ...   20   21   22   23   24   25   26   27   ...   183
Bog'liq
python3-oop

[
 14 
]
Let's describe our current chess set composition and add some attributes to the 
objects to hold the composite relationships:
+chess_set: ChessSet
+positions: Position
+chess_set: ChessSet
Player
Position
Piece
Chess Set
Board
+chess_board: Board
+pieces: list
+board: Board
Make Move
2
1
64
32
1
1
1
The composition relationship is represented in UML as a solid diamond. The hollow 
diamond represents the aggregate relationship. You'll notice that the board and 
pieces are stored as part of the chess set in exactly the same way a reference to them 
is stored as an attribute on the chess set. This shows that, once again, in practice, 
the distinction between aggregation and composition is often irrelevant once you 
get past the design stage. When implemented, they behave in much the same way. 
However, it can help to differentiate between the two when your team is discussing 
how the different objects interact. Often, you can treat them as the same thing, but 
when you need to distinguish between them, it's great to know the difference (this
is abstraction at work).
Inheritance
We discussed three types of relationships between objects: association, composition, 
and aggregation. However, we
have not fully specified our chess set, and these tools 
don't seem to give us all the power we need. We discussed the possibility that a player 
might be a human or it might be a piece of software featuring artificial intelligence. It 
doesn't seem right to say that a player is 
associated
with a human, or that the artificial 
intelligence implementation is 
part of
the player object. What we really need is the 
ability to say that "Deep Blue 
is a
player" or that "Gary Kasparov 
is a
player".
The 
is a
relationship is formed by 
inheritance
. Inheritance is the most famous, well-
known, and over-used relationship in object-oriented programming. Inheritance is sort 
of like a family tree. My grandfather's last name was Phillips and my father inherited 
that name. I inherited it from him (along with blue eyes and a penchant for writing). 
In object-oriented programming, instead of inheriting features and behaviors from a 
person, one class can inherit attributes and methods from another class.
www.it-ebooks.info


Chapter 1

Download 2,95 Mb.

Do'stlaringiz bilan baham:
1   ...   20   21   22   23   24   25   26   27   ...   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