7 Patterns-442-12-by6

G button pb new motifbutton bad button pb guifactory

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: object, rather than a function Object is instance of a Command abstract class Command has reversible method that returns boolean value Store command history in a list d) Pattern Command pattern Name Command or Action or Transaction Applicability Parameterize objects by actions they perform Specify, queue, and execute requests at different times Support undo functionality by storing context information in command instances Support change log for recovery purposes Specify a transaction-based system (e.g., a database) 71 72 Pattern Client Invoker Structure of Command pattern Command pattern Consequences: Pattern Receiver Action() Command Execute() 1. Decouple object receiving a request from object carrying out request Lexi example: Different icons can be associated with the same command 2. Commands are Girst class objects Easy to support undo and redo, functionality (e.g., add state info to commands to avoid error hysteresis) Copying of command objects may be required ... ConcreteCommand Execute() receiver state receiver->action(); 73 74 Command pattern Consequences (continued): Pattern Pattern Command pattern Implementation notes: 1. How much should command do vs. delegating to receiver 2. Support undo and redo functionality Keep commands in a queue associated with the same command Careful when deciding what commands to put in queue (e.g., do not put Gile commands or commands that did not change state in queue) 3. Avoid error accumulation in undo process (possibly use Memento pattern) 75 76 3. Use simple commands to form complex ones (e.g., support for editor macros) 4. Easy to extend commands (not tied to interface) Case study Spell-checking and hyphenation Support multiple functions/operations and also multiple algorithms for each function (e.g., multiple hyphenation algorithms) Adding new functions/operations over time Deal with scattered information (glyphs), and different implementations (children as arrays, lists, etc.) Deal with different traversal strategies for stored information -- E.g., suppor...
View Full Document

This note was uploaded on 02/23/2012 for the course COMP 553 taught by Professor Ajay during the Spring '12 term at Ill. Chicago.

Ask a homework question - tutors are online