Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet245/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   241   242   243   244   245   246   247   248   ...   288
Bog'liq
GOF Design Patterns

Design Patterns: Elements of Reusable Object-Oriented Software 
365 
void View::DoDisplay () { } 
Subclasses override it to add their specific drawing behavior: 
void MyView::DoDisplay () { 
// render the view's contents 

Known Uses 
Template methods are so fundamental that they can be found in almostevery abstract 
class. Wirfs-Brock et al. [WBWW90, WBJ90] provide a good overview anddiscussion 
of template methods. 
Related Patterns 
Factory Methods (121) are often called by template methods. In the Motivation 
example,the factory method DoCreateDocument is called by the template 
methodOpenDocument. 
Strategy (349): Template methods use inheritance to vary part of an 
algorithm.Strategies use delegation to vary the entire algorithm. 


Design Patterns: Elements of Reusable Object-Oriented Software 
366 
Visitor 
Intent 
Represent an operation to be performed on the elements of an objectstructure. 
Visitor lets you define a new operation without changing theclasses of the elements 
on which it operates. 
Motivation 
Consider a compiler that represents programs as abstract syntax trees.It will 
need to perform operations on abstract syntax trees for "staticsemantic" analyses 
like checking that all variables are defined. Itwill also need to generate code. 
So it might define operations fortype-checking, code optimization, flow analysis, 
checking for variablesbeing assigned values before they're used, and so on. 
Moreover, we coulduse the abstract syntax trees for pretty-printing, 
programrestructuring, code instrumentation, and computing various metrics of 
aprogram. 
Most of these operations will need to treat nodes that representassignment 
statements differently from nodes that represent variables orarithmetic 
expressions. Hence there will be one class for assignmentstatements, another for 
variable accesses, another for arithmeticexpressions, and so on. The set of node 
classes depends on the languagebeing compiled, of course, but it doesn't change 
much for a givenlanguage. 
This diagram shows part of the Node class hierarchy. The problem hereis that 
distributing all these operations across the various nodeclasses leads to a system 
that's hard to understand, maintain, andchange. It will be confusing to have 



Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   241   242   243   244   245   246   247   248   ...   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