Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet46/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   42   43   44   45   46   47   48   49   ...   288
Bog'liq
GOF Design Patterns

Design Patterns: Elements of Reusable Object-Oriented Software 
57 
make modifications to thecorresponding Glyph subclass to make it aware of the 
border. Our firstchoice, composing the glyph in the border, keeps the 
border-drawingcode entirely in the Border class, leaving other classes alone. 
What does the Border class look like? The fact that borders have anappearance 
suggests they should actually be glyphs; that is, Bordershould be a subclass of 
Glyph. But there's a more compelling reasonfor doing this: Clients shouldn't care 
whether glyphs have borders ornot. They should treat glyphs uniformly. When clients 
tell a plain,unbordered glyph to draw itself, it should do so withoutembellishment. 
If that glyph is composed in a border, clientsshouldn't have to treat the border 
containing the glyph anydifferently; they just tell it to draw itself as they 
told the plainglyph before. This implies that the Border interface matches the 
Glyphinterface. We subclass Border from Glyph to guarantee thisrelationship. 
All this leads us to the concept of 
transparent enclosure
,which combines the 
notions of (1) single-child (orsingle-
component
) composition and (2) 
compatibleinterfaces. Clients generally can't tell whether they're dealing 
withthe component or its 
enclosure
(i.e., the child's parent),especially if the 
enclosure simply delegates all its operations to itscomponent. But the enclosure 
can also 
augment
the component'sbehavior by doing work of its own before and/or 
after delegating anoperation. The enclosure can also effectively add state to 
thecomponent. We'll see how next. 
Monoglyph 
We can apply the concept of transparent enclosure to all glyphs thatembellish 
other glyphs. To make this concept concrete, we'll define asubclass of Glyph called 
MonoGlyph
to serve as an abstractclass for "embellishment glyphs," likeBorder 
(see Figure 2.7).MonoGlyph stores a reference to a component and forwards all 
requests toit. That makes MonoGlyph totally transparent to clients by default.For 
example, MonoGlyph implements the Draw operation like this: 
void MonoGlyph::Draw (Window* w) {
_component->Draw(w);




Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   42   43   44   45   46   47   48   49   ...   288




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