Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



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

Design Patterns: Elements of Reusable Object-Oriented Software 
83 
void PreorderIterator::Next () { 
Iterator* i = _iterators.Top()->CurrentItem()->CreateIterator(); 
i->First(); 
_iterators.Push(i); 
while ( _iterators.Size() > 0 && _iterators.Top()->IsDone() ) { 
delete _iterators.Pop(); 
_iterators.Top()->Next(); 


Notice how the Iterator class hierarchy lets us add new kinds oftraversals without 
modifying glyph classes

we simply subclassIterator and add a new traversal as 
we have withPreorderIterator. Glyph subclasses use the sameinterface to give 
clients access to their children without revealingthe underlying data structure 
they use to store them. Becauseiterators store their own copy of the state of 
a traversal, we cancarry on multiple traversals simultaneously, even on the 
samestructure. And though our traversals have been over glyph structuresin this 
example, there's no reason we can't parameterize a class likePreorderIterator 
by the type of object in the structure.We'd use templates to do that in C++. Then 
we can reuse the machineryin PreorderIterator to traverse other structures. 
Iterator Pattern 
The Iterator (289) pattern captures these techniquesfor supporting access and 
traversal over object structures. It'sapplicable not only to composite structures 
but to collections aswell. It abstracts the traversal algorithm and shields clients 
fromthe internal structure of the objects they traverse. The Iteratorpattern 
illustrates once more how encapsulating the concept thatvaries helps us gain 
flexibility and reusability. Even so, theproblem of iteration has surprising depth, 
and the Iterator patterncovers many more nuances and trade-offs than we've 
considered here. 
Traversal versus Traversal Actions 
Now that we have a way of traversing the glyph structure, we need tocheck the 
spelling and do the hyphenation. Both analyses involveaccumulating information 
during the traversal. 
First we have to decide where to put the responsibility for analysis.We could 
put it in the Iterator classes, thereby making analysis anintegral part of 
traversal. But we get more flexibility and potentialfor reuse if we distinguish 
between the traversal and the actionsperformed during traversal. That's because 



Download 4,06 Mb.

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