Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



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

Design Patterns: Elements of Reusable Object-Oriented Software 
298 
List* employees
// ... 
ListIterator forward(employees); 
ReverseListIterator backward(employees); 
PrintEmployees(forward); 
PrintEmployees(backward); 
4.
Avoiding commitment to a specific list implementation.
Let's consider how 
a skiplist variation of List would affectour iteration code. A SkipList 
subclass ofList must provide a SkipListIterator thatimplements the 
Iterator interface. Internally, theSkipListIterator has to keep more than 
just an index todo the iteration efficiently. But sinceSkipListIterator 
conforms to theIterator interface, the PrintEmployees operationcan also 
be used when the employees are stored in a SkipListobject. 
SkipList* employees; 
// ... 
SkipListIterator iterator(employees); 
PrintEmployees(iterator); 
Although this approach works, it would be better if we didn't have to 
committo a specific List implementation, namelySkipList. We can introduce 
an AbstractListclass to standardize the list interface for different 
listimplementations. List and SkipList becomesubclasses of AbstractList. 
To enable polymorphic iteration, AbstractList defines afactory method 
CreateIterator, which subclasses override toreturn their corresponding 
iterator: 
template  
class AbstractList { 
public: 
virtual Iterator* CreateIterator() const = 0; 
// ...
}; 
An alternative would be to define a general mixin classTraversable that 
defines the interface for creating aniterator. Aggregate classes can mix 
inTraversable to support polymorphic iteration. 
List overrides CreateIterator to return aListIterator object: 
template  
Iterator* List::CreateIterator () const { 
return new ListIterator(this);



Download 4,06 Mb.

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