Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet144/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   140   141   142   143   144   145   146   147   ...   288
Bog'liq
GOF Design Patterns

Design Patterns: Elements of Reusable Object-Oriented Software 
206 
The Stream abstract class maintains an internal buffer and provides operations 
for storing data onto the stream (PutInt, PutString). Whenever the buffer is full, 
Stream calls the abstract operation HandleBufferFull, which does the actual data 
transfer. The FileStream version of this operation overrides this operation to 
transfer the buffer to a file. 
The key class here is StreamDecorator, which maintains a reference to a component 
stream and forwards requests to it. StreamDecorator subclasses override 
HandleBufferFull and perform additional actions before calling StreamDecorator's 
HandleBufferFull operation. 
For example, the CompressingStream subclass compresses the data, and the 
ASCII7Stream converts the data into 7-bit ASCII. Now, to create a FileStream that 
compresses its data 
and
converts the compressed binary data to 7-bit ASCII, we 
decorate a FileStream with a CompressingStream and an ASCII7Stream: 
Stream* aStream = new CompressingStream( 
new ASCII7Stream( 
new FileStream("aFileName") 

); 
aStream->PutInt(12); 
aStream->PutString("aString"); 
Related Patterns 
Adapter (157): A decorator is different from an adapter in that a decorator only 
changes an object's responsibilities, not its interface; an adapter will give 
an object a completely new interface. 


Design Patterns: Elements of Reusable Object-Oriented Software 
207 
Composite (183): A decorator can be viewed as a degenerate composite with only 
one component. However, a decorator adds additional responsibilities

it isn't 
intended for object aggregation. 
Strategy (349): A decorator lets you change the skin of an object; a strategy 
lets you change the guts. These are two alternative ways of changing an object. 



Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   140   141   142   143   144   145   146   147   ...   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