Design Patterns : Elements of Reusable Object-Oriented Software



Download 4,06 Mb.
Pdf ko'rish
bet181/288
Sana07.04.2022
Hajmi4,06 Mb.
#535140
1   ...   177   178   179   180   181   182   183   184   ...   288
Bog'liq
GOF Design Patterns

Implementation 
Consider the following issues when implementing the Command pattern: 
1.
How intelligent should a command be?
A command can have a wide range of 
abilities. At one extreme itmerely defines a binding between a receiver 
and the actions that carryout the request. At the other extreme it implements 
everything itselfwithout delegating to a receiver at all. The latter extreme 
is usefulwhen you want to define commands that are independent of 
existingclasses, when no suitable receiver exists, or when a command knows 
itsreceiver implicitly. For example, a command that creates 
anotherapplication window may be just as capable of creating the window 
asany other object. Somewhere in between these extremes are commandsthat 
have enough knowledge to find their receiver dynamically. 
2.
Supporting undo and redo.
Commands can support undo and redo capabilities 
if they provide a wayto reverse their execution (e.g., an Unexecute or Undo 
operation). AConcreteCommand class might need to store additional state 
to do so. Thisstate can include 
o
the Receiver object, which actually carries out operations 
inresponse to the request, 
o
the arguments to the operation performed on the receiver, and 
o
any original values in the receiver that can changeas a result of 
handling the request. The receiver must provideoperations that let 
the command return the receiver to its prior state. 
To support one level of undo, an application needs to store only thecommand 
that was executed last. For multiple-level undo and redo, theapplication 
needs a 
history list
of commands that havebeen executed, where the maximum 
length of the list determines thenumber of undo/redo levels. The history 
list stores sequences ofcommands that have been executed. Traversing 
backward through thelist and reverse-executing commands cancels their 
effect; traversingforward and executing commands reexecutes them. 
An undoable command might have to be copied before it can be placed onthe 
history list. That's because the command object that carried outthe original 



Download 4,06 Mb.

Do'stlaringiz bilan baham:
1   ...   177   178   179   180   181   182   183   184   ...   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