Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet196/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   192   193   194   195   196   197   198   199   ...   288
Bog'liq
GOF Design Patterns

Design Patterns: Elements of Reusable Object-Oriented Software 
291 
corresponding iterator. Thisrequires an operation like CreateIterator through 
which clientsrequest an iterator object. 
CreateIterator is an example of a factory method (see Factory Method (121)). We 
use it here to let a client aska list object for the appropriate iterator. The 
Factory Methodapproach give rise to two class hierarchies, one for lists and 
anotherfor iterators. The CreateIterator factory method "connects" the 
twohierarchies. 
Applicability 
Use the Iterator pattern 

to access an aggregate object's contents without exposing its 
internalrepresentation. 

to support multiple traversals of aggregate objects. 

to provide a uniform interface for traversing different 
aggregatestructures (that is, to support polymorphic iteration). 
Structure 
Participants 

Iterator
o
defines an interface for accessing and traversing elements.

ConcreteIterator
o
implements the Iterator interface. 


Design Patterns: Elements of Reusable Object-Oriented Software 
292 
o
keeps track of the current position in the traversal of the aggregate. 

Aggregate
o
defines an interface for creating an Iterator object. 

ConcreteAggregate
o
implements the Iterator creation interface to return an instance 
of the proper ConcreteIterator. 
Collaborations 

A ConcreteIterator keeps track of the current object in theaggregate and 
can compute the succeeding object in thetraversal. 
Consequences 
The Iterator pattern has three important consequences: 
1.
It supports variations in the traversal of an aggregate.
Complex aggregates 
may be traversed in many ways. For example, codegeneration and semantic 
checking involve traversing parse trees. Codegeneration may traverse the 
parse tree inorder or preorder.Iterators make it easy to change the 
traversal algorithm: Just replacethe iterator instance with a different 
one. You can also defineIterator subclasses to support new traversals. 
2.
Iterators simplify the Aggregate interface.
Iterator's traversal interface 
obviates the need for a similarinterface in Aggregate, thereby simplifying 
the aggregate's interface. 
3.
More than one traversal can be pending on an aggregate.
An iterator keeps 
track of its own traversal state. Therefore you canhave more than one 
traversal in progress at once. 
Implementation 
Iterator has many implementation variants and alternatives. Someimportant ones 
follow. The trade-offs often depend on thecontrol structures your language 
provides. Some languages (CLU [LG86], for example) even support this pattern 
directly. 
1.
Who controls the iteration?
A fundamental issue is deciding which party 
controls the iteration,the iterator or the client that uses the iterator. 
When the clientcontrols the iteration, the iterator is called an 

Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   192   193   194   195   196   197   198   199   ...   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