Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



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

Design Patterns: Elements of Reusable Object-Oriented Software 
294 
operations might prove useful. For example, orderedaggregates can have a 
Previous operation that positions the iteratorto the previous element. A 
SkipTo operation is useful for sorted orindexed collections. SkipTo 
positions the iterator to an objectmatching specific criteria. 
5.
Using polymorphic iterators in C++.
Polymorphic iterators have their cost. 
They require the iteratorobject to be allocated dynamically by a factory 
method. Hence theyshould be used only when there's a need for polymorphism. 
Otherwiseuse concrete iterators, which can be allocated on the stack. 
Polymorphic iterators have another drawback: the client is responsiblefor 
deleting them. This is error-prone, because it's easy to forgetto free a 
heap-allocated iterator object when you're finished with it.That's 
especially likely when there are multiple exit points in anoperation. And 
if an exception is triggered, the iterator object willnever be freed. 
The Proxy (233) pattern provides a remedy. We can use astack-allocated proxy 
as a stand-in for the real iterator. The proxydeletes the iterator in its 
destructor. Thus when the proxy goes outof scope, the real iterator will 
get deallocated along with it. Theproxy ensures proper cleanup, even in 
the face of exceptions. Thisis an application of the well-known C++ 
technique "resourceallocation is initialization" [ES90]. The Sample Code 
givesan example. 
6.
Iterators may have privileged access.
An iterator can be viewed as an 
extension of the aggregate thatcreated it. The iterator and the aggregate 
are tightly coupled. Wecan express this close relationship in C++ by making 
the iterator afriend of its aggregate. Then you don't need todefine 
aggregate operations whose sole purpose is to let iteratorsimplement 
traversal efficiently. 
However, such privileged access can make defining new traversalsdifficult, 
since it'll require changing the aggregate interface to addanother friend. 
To avoid this problem, the Iterator class can includeprotected operations 
for accessing important but publiclyunavailable members of the aggregate. 
Iterator subclasses (and 
only
Iterator subclasses) may use these protected 
operations to gainprivileged access to the aggregate. 
7.
Iterators for composites.
External iterators can be difficult to implement 
over recursiveaggregate structures like those in the Composite (183) 
pattern, because a position in the structure may span many levels ofnested 
aggregates. Therefore an external iterator has to store a paththrough the 
Composite to keep track of the current object. Sometimesit's easier just 
to use an internal iterator. It can record thecurrent position simply by 



Download 4,06 Mb.

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