Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet51/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   47   48   49   50   51   52   53   54   ...   288
Bog'liq
GOF Design Patterns

Design Patterns: Elements of Reusable Object-Oriented Software 
63 
Figure 2.10: Abstract product classes and concrete subclasses 
The last question we have to answer is, Where does the GUIFactoryinstance come 
from? The answer is, Anywhere that's convenient. Thevariable guiFactory could 
be a global, a static member of awell-known class, or even a local variable if 
the entire user interface iscreated within one class or function. There's even 
a design pattern,Singleton (144), for managing well-known, one-of-a-kindobjects 
like this. The important thing, though, is to initializeguiFactory at a point 
in the program 
before
it's ever usedto create widgets but 
after
it's clear which 
look and feel isdesired. 
If the look and feel is known at compile-time, then guiFactorycan be initialized 
with a simple assignment of a new factory instanceat the beginning of the program: 
GUIFactory* guiFactory = new MotifFactory; 
If the user can specify the look and feel with a string name atstartup time, then 
the code to create the factory might be 
GUIFactory* guiFactory; 
const char* styleName = getenv("LOOK_AND_FEEL"); 
// user or environment supplies this at startup 
if (strcmp(styleName, "Motif") == 0) { 
guiFactory = new MotifFactory;
} else if (strcmp(styleName, "Presentation_Manager") == 0) { 
guiFactory = new PMFactory;


Design Patterns: Elements of Reusable Object-Oriented Software 
64 
} else { 
guiFactory = new DefaultGUIFactory;

There are more sophisticated ways to select the factory at run-time.For example, 
you could maintain a registry that maps strings tofactory objects. That lets you 
register instances of new factorysubclasses without modifying existing code, as 
the preceding approach requires. And you don't have to link all platform-specific 
factoriesinto the application. That's important, because it might not bepossible 
to link a MotifFactory on a platform that doesn't supportMotif. 
But the point is that once we've configured the application with theright factory 
object, its look and feel is set from then on. If wechange our minds, we can 
reinitialize guiFactory with afactory for a different look and feel and then 
reconstruct theinterface. Regardless of how and when we decide to 
initializeguiFactory, we know that once we do, the application cancreate the 
appropriate look and feel without modification. 

Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   47   48   49   50   51   52   53   54   ...   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