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
Копасов Игорь (1), Т Е Л Е Ф О Н О Г Р А М М А ЗООМ, 20201546 п.80 использ., Oliy matematika, презентация индустрия мутакил иши, 3000 most common words in English, Sun'iy intellekt, 1638511850 AE, 1638511850 AE, Hisob-raqan (Patent boji), O'RQ-600 23-MODDA, Talabaning haftalik hisoboti namunasi , iikinchi hafta amaliyoti., Таҳлил тест
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 2022
ma'muriyatiga murojaat qiling

    Bosh sahifa
davlat universiteti
ta’lim vazirligi
axborot texnologiyalari
maxsus ta’lim
zbekiston respublikasi
guruh talabasi
O’zbekiston respublikasi
nomidagi toshkent
o’rta maxsus
davlat pedagogika
texnologiyalari universiteti
toshkent axborot
xorazmiy nomidagi
rivojlantirish vazirligi
pedagogika instituti
Ўзбекистон республикаси
tashkil etish
haqida tushuncha
таълим вазирлиги
vazirligi muhammad
O'zbekiston respublikasi
toshkent davlat
махсус таълим
respublikasi axborot
kommunikatsiyalarini rivojlantirish
vazirligi toshkent
saqlash vazirligi
fanidan tayyorlagan
bilan ishlash
Toshkent davlat
sog'liqni saqlash
uzbekistan coronavirus
respublikasi sog'liqni
coronavirus covid
koronavirus covid
vazirligi koronavirus
risida sertifikat
covid vaccination
qarshi emlanganlik
sertifikat ministry
vaccination certificate
Ishdan maqsad
fanidan mustaqil
matematika fakulteti
o’rta ta’lim
haqida umumiy
fanlar fakulteti
pedagogika universiteti
ishlab chiqarish
moliya instituti
fanining predmeti