Pattern:
Command Processor


Author

Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, and Michael Stal

Intent

"The Command Processor design pattern separates the request for a service from its execution. A command processor component manages requests as separate objects, schedules their execution, and provides additional services such as the storing of request objects for later undo." (Buschmann, F., R. Meunier, H. Rohnert, P. Sommerlad, M. Stal. Pattern-Oriented Software Architecture: A System Of Patterns. West Sussex, England: John Wiley & Sons Ltd., 1996)

Motivation

The Command Processor pattern builds on the Command design pattern. Both patterns follow the idea of encapsulating requests into objects. Whenever a user calls a specific function of the application, the request is turned into a command object. The Command Processor pattern illustrates more specifically how command objects are managed. A central component of the Command Processor pattern description takes care of all command objects. The command processor schedules the execution of commands, may store them for later undo, and may provide other services such as logging the sequence of commands for testing purposes. Each command object delegates the execution of its task to supplier components within the functional core of the application. For a more detailed Motivation description for this pattern see: Buschmann, F., R. Meunier, H. Rohnert, P. Sommerlad, and M. Stal. Pattern-Oriented Software Architecture: A System Of Patterns. West Sussex, England: John Wiley & Sons Ltd., 1996.

Known Uses

This pattern has been used on the following systems: In ET++ a framework of command processors supports unlimited, bounded, and single undo and redo. (Weinand, A., E. Gamma, R. Marty, ET++ - An Object-Oriented Application Framework in C++, in Proceedings of OOPSLA 88, pp. 46-57, San Diego, 1988.) MacApp provides undoable operations using the Command Procesor pattern. (Apple Computer Inc., Macintosh Programmers Workshop Pascal 3.0 Reference, Cupertino, CA, 1989.) An included action class (abstract base class) in InterViews provides the functionality of a command component. (Linton, M., P. Calder, J. Interrante, S. Tang, J. Vlissides, InterViews Reference Manual, CSL, Stanford University, 3.1 edition, 1992.) ATM-P uses a hierarchy of command classes to pass around command objects. The command object receiver decides how the object will be executed. Each process implements its own command processor. (Siemens AG, ATM-P: Komplexspezifikation, internal document, 1993.) SICAT provides a well-defined undo facility in the control program and the graphical SDL editors using the Command Processor pattern. (Siemens AG, SICAT Steuerprogramm: Entwurfsspezifikation, internal document no. P30308-A6331-A000-02-D8.)

See Also

Command pattern

Thumbnail

Keywords

Command pattern, Command Processor, Command Processor pattern, Buschmann patterns, design patterns, support undo, request manager

Business Domains

applications that provide services related to the execution of user functions, such as undointeractive applications with a flexible human-computer interface

Problem Forces

changes to the user interface should be possible at runtimeextending behaviors of an existing hierarchy is impracticalneed separation of a request for a service from the executionneed to break up many behaviors with multiple conditionsneed to enhance an existing application without breaking existing codeneed undo capabilitypermit users to work with an application in different waysthere is more than one object that may handle a request

Benefits

efficiency by parallel processingenhanced maintainability and extensibility of the systemflexibility in the number and functionality of requestsflexibility in the way requests are activatedprovides a mechanism for decreasing the number of conditional statements

Liabilities

class hierarchies become unmanageablecomplexity of design and implementationincreased number of objectsresults in many small objects looking very similar

Implementation Files

Simple implementation of the pattern - Supplier. Supplier.javaSimple implementation of the pattern - Controller. Controller.javaSimple implementation of the pattern - CommandProcessor. CommandProcessor.javaSimple implementation of the pattern - Command. Command.javaSimple implementation of the pattern - AbstractCommand. AbstractCommand.javaSimple implementation of the pattern. commandprocessor.h



Generated on Fri Oct 20 10:42:15 GMT+02:00 2000 by Framework Studio