Design Patterns : Elements of Reusable Object-Oriented Software


Encapsulating the Analysis



Download 4,06 Mb.
Pdf ko'rish
bet68/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   64   65   66   67   68   69   70   71   ...   288
Bog'liq
GOF Design Patterns

Encapsulating the Analysis 
From all indications, we need to encapsulate the analysis in aseparate object, 
much like we've done many times before. We could putthe machinery for a given 
analysis into its own class. We could usean instance of this class in conjunction 
with an appropriate iterator.The iterator would "carry" the instance to each glyph 
in thestructure. The analysis object could then perform a piece of theanalysis 
at each point in the traversal. The analyzer accumulatesinformation of interest 
(characters in this case) as the traversalproceeds: 


Design Patterns: Elements of Reusable Object-Oriented Software 
85 
The fundamental question with this approach is how the analysis 
objectdistinguishes different kinds of glyphs without resorting to typetests or 
downcasts. We don't want a SpellingChecker classto include (pseudo)code like 
void SpellingChecker::Check (Glyph* glyph) { 
Character* c; 
Row* r; 
Image* i; 
if (c = dynamic_cast(glyph)) { 
// analyze the character 
} else if (r = dynamic_cast(glyph)) { 
// prepare to analyze r's children 
} else if (i = dynamic_cast(glyph)) { 
// do nothing 


This code is pretty ugly. It relies on fairly esoteric capabilitieslike type-safe 
casts. It's hard to extend as well. We'll have toremember to change the body of 
this function whenever we change theGlyph class hierarchy. In fact, this is the 
kind of code thatobject-oriented languages were intended to eliminate. 
We want to avoid such a brute-force approach, but how? Let's considerwhat happens 
when we add the following abstract operation to the Glyphclass: 
void CheckMe(SpellingChecker&) 
We define CheckMe in every Glyph subclass as follows: 



Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   64   65   66   67   68   69   70   71   ...   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