Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet202/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   198   199   200   201   202   203   204   205   ...   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 
299 

Now we're in a position to write the code for printingthe employees 
independent of a concrete representation. 
// we know only that we have an AbstractList 
AbstractList* employees
// ... 
Iterator* iterator = employees->CreateIterator(); 
PrintEmployees(*iterator); 
delete iterator
5.
Making sure iterators get deleted.
Notice that CreateIterator returns a 
newly allocatediterator object. We're responsible for deleting it. If we 
forget,then we've created a storage leak. To make life easier for 
clients,we'll provide an IteratorPtr that acts as a proxy for aniterator. 
It takes care of cleaning up the Iterator objectwhen it goes out of scope. 
IteratorPtr is always allocated on thestack.
5
C++ automatically takes care 
of callingits destructor, which deletes the real iterator.IteratorPtr 
overloads bothoperator-> andoperator* in such a way that an IteratorPtr 
can betreated just like a pointer to an iterator. The members ofIteratorPtr 
are all implemented inline; thus they can incur nooverhead. 
template  
class IteratorPtr { 
public: 
IteratorPtr(Iterator* i): _i(i) { } 
~IteratorPtr() { delete _i; } 
Iterator* operator->() { return _i; } 
Iterator& operator*() { return *_i; } 
private: 
// disallow copy and assignment to avoid 
// multiple deletions of _i: 
IteratorPtr(const IteratorPtr&); 
IteratorPtr& operator=(const IteratorPtr&); 
private: 
Iterator* _i; 
}; 
IteratorPtr lets us simplify our printing code: 
AbstractList* employees; 
// ... 
IteratorPtr iterator(employees->CreateIterator()); 



Download 4,06 Mb.

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