Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet199/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   195   196   197   198   199   200   201   202   ...   288
Bog'liq
GOF Design Patterns

Design Patterns: Elements of Reusable Object-Oriented Software 
295 
calling itself recursively, thereby storingthe path implicitly in the call 
stack. 
If the nodes in a Composite have an interface for moving from a nodeto its 
siblings, parents, and children, then a cursor-based iteratormay offer a 
better alternative. The cursor only needs to keep track ofthe current node; 
it can rely on the node interface to traverse theComposite. 
Composites often need to be traversed in more than one way. 
Preorder,postorder, inorder, and breadth-first traversals are common. You 
cansupport each kind of traversal with a different class of iterator. 
8.
Null iterators.

NullIterator
is a degenerate iterator that's helpful 
forhandling boundary conditions. By definition, a NullIterator is 
always
done with traversal; that is, its IsDone operation alwaysevaluates to true. 
NullIterator can make traversing tree-structured aggregates 
(likeComposites) easier. At each point in the traversal, we ask thecurrent 
element for an iterator for its children. Aggregate elementsreturn a 
concrete iterator as usual. But leaf elements return aninstance of 
NullIterator. That lets us implement traversal over theentire structure 
in a uniform way. 
Sample Code 
We'll look at the implementation of a simple List class, which is partof our 
foundation library (Appendix C) .We'll show two Iterator implementations, one 
for traversing the List infront-to-back order, and another for traversing 
back-to-front (thefoundation library supports only the first one). Then we show 
how touse these iterators and how to avoid committing to a particularimplementation. 
After that, we change the design to make sureiterators get deleted properly. The 
last example illustrates aninternal iterator and compares it to its external 
counterpart. 
1.
List and Iterator interfaces.
First let's look at the part of the List 
interface that's relevant toimplementing iterators. Refer to (Appendix C). 
for the full interface. 
template  
class List { 
public: 
List(long size = DEFAULT_LIST_CAPACITY); 
long Count() const; 
Item& Get(long index) const; 



Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   195   196   197   198   199   200   201   202   ...   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