Design Patterns : Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet112/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   108   109   110   111   112   113   114   115   ...   288
Bog'liq
GOF Design Patterns

Related Patterns 
Many patterns can be implemented using the Singleton pattern. See Abstract Factory 
(99), Builder (110), and Prototype (133). 


Design Patterns: Elements of Reusable Object-Oriented Software 
153 
Discussion of Creational Patterns 
There are two common ways to parameterize a system by the classes ofobjects it 
creates. One way is to subclass the class that creates theobjects; this corresponds 
to using the Factory Method (121) pattern. The main drawback of thisapproach is 
that it can require creating a new subclass just to changethe class of the product. 
Such changes can cascade. For example,when the product creator is itself created 
by a factory method, thenyou have to override its creator as well. 
The other way to parameterize a system relies more on objectcomposition: Define 
an object that's responsible for knowing the classof the product objects, and 
make it a parameter of the system. Thisis a key aspect of the Abstract Factory 
(99),Builder (110), and Prototype (133) patterns. All three involve creating a 
new "factory object" whoseresponsibility is to create product objects. Abstract 
Factory has thefactory object producing objects of several classes. Builder has 
thefactory object building a complex product incrementally using acorrespondingly 
complex protocol. Prototype has the factory objectbuilding a product by copying 
a prototype object. In this case, thefactory object and the prototype are the 
same object, because theprototype is responsible for returning the product. 
Consider the drawing editor framework described in the Prototypepattern. There 
are several ways to parameterize a GraphicTool by theclass of product: 

By applying the Factory Method pattern, a subclass of GraphicTool will 
becreated for each subclass of Graphic in the palette. GraphicTool willhave 
a NewGraphic operation that each GraphicTool subclass willredefine. 

By applying the Abstract Factory pattern, there will be a class hierarchyof 
GraphicsFactories, one for each Graphic subclass. Each factorycreates just 
one product in this case: CircleFactory will createCircles, LineFactory 
will create Lines, and so on. A GraphicTool willbe parameterized with a 
factory for creating the appropriate kind ofGraphics. 

By applying the Prototype pattern, each subclass of Graphics willimplement 
the Clone operation, and a GraphicTool will be parameterizedwith a prototype 
of the Graphic it creates. 
Which pattern is best depends on many factors. In our drawing editorframework, 
the Factory Method pattern is easiest to use at first.It's easy to define a new 
subclass of GraphicTool, and the instancesof GraphicTool are created only when 
the palette is defined. The maindisadvantage here is that GraphicTool subclasses 
proliferate, and noneof them does very much. 
Abstract Factory doesn't offer much of an improvement, because itrequires an 
equally large GraphicsFactory class hierarchy. AbstractFactory would be 
preferable to Factory Method only if there werealready a GraphicsFactory class 



Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   108   109   110   111   112   113   114   115   ...   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