Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet155/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   151   152   153   154   155   156   157   158   ...   288
Bog'liq
GOF Design Patterns

Design Patterns: Elements of Reusable Object-Oriented Software 
224 
In our document editor, for example, we can store a map of typographic 
information in a separate structure rather than store the font and type 
style with each character object. The map keeps track of runs of characters 
with the same typographic attributes. When a character draws itself, it 
receives its typographic attributes as a side-effect of the draw traversal. 
Because documents normally use just a few different fonts and styles, 
storing this information externally to each character object is far more 
efficient than storing it internally. 
2.
Managing shared objects.
Because objects are shared, clients shouldn't 
instantiate them directly. FlyweightFactory lets clients locate a 
particular flyweight. FlyweightFactory objects often use an associative 
store to let clients look up flyweights of interest. For example, the 
flyweight factory in the document editor example can keep a table of 
flyweights indexed by character codes. The manager returns the proper 
flyweight given its code, creating the flyweight if it does not already 
exist.
Sharability also implies some form of reference counting or garbage 
collection to reclaim a flyweight's storage when it's no longer needed. 
However, neither is necessary if the number of flyweights is fixed and small 
(e.g., flyweights for the ASCII character set). In that case, the flyweights 
are worth keeping around permanently. 
Sample Code 
Returning to our document formatter example, we can define a Glyph base class 
for flyweight graphical objects. Logically, glyphs are Composites (see Composite 
(183)) that have graphical attributes and can draw themselves. Here we focus on 
just the font attribute, but the same approach can be used for any other graphical 
attributes a glyph might have. 
class Glyph { 
public: 
virtual ~Glyph(); 
virtual void Draw(Window*, GlyphContext&); 
virtual void SetFont(Font*, GlyphContext&); 
virtual Font* GetFont(GlyphContext&); 
virtual void First(GlyphContext&); 



Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   151   152   153   154   155   156   157   158   ...   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