Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



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

Design Patterns: Elements of Reusable Object-Oriented Software 
368 
With the Visitor pattern, you define two class hierarchies: one for theelements 
being operated on (the Node hierarchy) and one for the visitorsthat define 
operations on the elements (the NodeVisitor hierarchy). Youcreate a new operation 
by adding a new subclass to the visitor classhierarchy. As long as the grammar 
that the compiler accepts doesn'tchange (that is, we don't have to add new Node 
subclasses), we can addnew functionality simply by defining new NodeVisitor 
subclasses. 
Applicability 
Use the Visitor pattern when 

an object structure contains many classes of objects with differing 
interfaces, and you want to perform operations on these objects that depend 
on their concrete classes. 

many distinct and unrelated operations need to be performed on objectsin 
an object structure, and you want to avoid "polluting" theirclasses with 
these operations. Visitor lets you keep related operationstogether by 
defining them in one class. When the object structure isshared by many 
applications, use Visitor to put operations in just thoseapplications that 
need them. 

the classes defining the object structure rarely change, but you oftenwant 
to define new operations over the structure. Changing the objectstructure 
classes requires redefining the interface to all visitors,which is 
potentially costly. If the object structure classes changeoften, then it's 
probably better to define the operations in those classes. 


Design Patterns: Elements of Reusable Object-Oriented Software 
369 
Structure 
Participants 

Visitor
(NodeVisitor) 
o
declares a Visit operation for each class of ConcreteElement in the 
object structure. The operation's name and signature identifies the 
class that sends the Visit request to the visitor. That lets the 
visitor determine the concrete class of the element being visited. 
Then the visitor can access the element directly through its 
Download 4,06 Mb.

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