Command patternSynopsis or Intent: Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operationsContext: You want to model the time evolution of a program: What needs to be done, e.g. queued requests, alarms, conditions for action What is being done, e.g. which parts of a composite or distributed action have been completed What has been done, e.g. a log of undoable operationsWhat are some applications that need to support undo? Editor, calculator, database with transactions Perform an execute at one time, undo at a different timeSolution: represent units of work as Command objects Interface of a Command object can be a simple execute() method Extra methods can support undo and redo Commands can be persistent and globally accessible, just lik
đang được dịch, vui lòng đợi..
