Design Patterns : Elements of Reusable Object-Oriented Software


Design Patterns: Elements of Reusable Object-Oriented Software



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

Design Patterns: Elements of Reusable Object-Oriented Software 
269 
request, say, from a MenuItem, will perform otherrequests at later times. 
Copying is required to distinguish differentinvocations of the same command 
if its state can vary acrossinvocations. 
For example, a DeleteCommand that deletes selected objects must 
storedifferent sets of objects each time it's executed. Therefore 
theDeleteCommand object must be copied following execution, and the copyis 
placed on the history list. If the command's state never changeson execution, 
then copying is not required

only a reference to thecommand need be placed 
on the history list. Commands that must becopied before being placed on 
the history list act as prototypes (see Prototype (133)). 
3.
Avoiding error accumulation in the undo process.
Hysteresis can be a problem 
in ensuring a reliable,semantics-preserving undo/redo mechanism. Errors 
can accumulate ascommands are executed, unexecuted, and reexecuted 
repeatedly so thatan application's state eventually diverges from original 
values. Itmay be necessary therefore to store more information in the 
command toensure that objects are restored to their original state. The 
Memento (316) pattern can be applied to give the commandaccess to this 
information without exposing the internals of otherobjects. 
4.
Using C++ templates.
For commands that (1) aren't undoable and (2) don't 
require arguments,we can use C++ templates to avoid creating a Command 
subclass forevery kind of action and receiver. We show how to do this in 
the SampleCode section. 
Sample Code 
The C++ code shown here sketches the implementation of the Command classesin the 
Motivation section. We'll define OpenCommand,PasteCommand, and MacroCommand. 
First theabstract Command class: 
class Command { 
public: 
virtual ~Command(); 
virtual void Execute() = 0; 
protected: 
Command(); 
}; 
OpenCommand opens a document whose name is supplied by theuser. An OpenCommand 
must be passed anApplication object in its constructor. AskUser is 
animplementation routine that prompts the user for the name of thedocument to 
open. 



Download 4,06 Mb.

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