Your SlideShare is downloading. ×
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Command Pattern
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Command Pattern


Published on

Presentation given on Nov 2006 at Melbourne Patterns Group

Presentation given on Nov 2006 at Melbourne Patterns Group

Published in: Technology, Business
1 Like
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Command Pattern Also Known As Action, Transaction
  • 2. Intent
    • Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
  • 3. Motivation
    • To issue requests to objects without knowing anything about the operation being requested or the receiver of the request.
  • 4. Example
  • 5. Applicability
    • O-O replacement for call-back function
    • Specify, queue & execute requests at different times
    • Support Undo
    • Log changes to be reapplied on a crash
    • Model system in terms of high-level transactions are build on primitive operations.
  • 6. Structure
  • 7. Collaborations
  • 8. Consequences
    • Decouples invoker from implementation of response
    • Commands are first-class objects.
    • Composite Commands
    • Easy to add new commands
  • 9. Related Patterns
    • A Composite can be used to implement Macro-Commands.
    • A Memento can keep state the command requires to undo its effect.
    • A command that must be copied before being placed on the history list acts as a Prototype.
  • 10. “ Unit of Work” as a collection of Commands Craig Larman
    • Register inserts, updates and delete
    • Sort for Referential Integrity
    • Commit
    • Uses Unit of Work Pattern from Patterns of Enterprise Application Architecture by Martin Fowler
  • 11. Command Processor POSA Buschmann et al Pattern-Oriented Software Architecture
    • Example from Craig Larman (Applying UML and Patterns)
      • Server-side request handling
        • Queue, log, prioritize and execute commands
  • 12. Command Processor Intent
    • Manages requests as separate objects, schedules their execution and provides additional services such as the storing of request object for later undo.
  • 13. Command Processor Applicability
    • Different modes of user interaction
    • External control of application via scripting language
    • Implementing crosscutting services e.g. undo, redo, macros, logging, requesting scheduling and suspension.
  • 14. Command Processor Benefits
    • Flexibility in the way requests are activated.
    • Flexibility in the number and functionality of requests.
    • Programming execution-related services.
    • Testability at application level.
    • Concurrency.
  • 15. Command Processor Liabilities
    • Efficiency loss.
    • Potential for an excessive number of command classes.
      • Grouping commands
      • Passing the supplier object as parameter for simple objects
      • Macro-command objects that are combinations of simpler commands.
    • Complexity in acquiring command parameters
  • 16. Command Processor Variants
    • Spread controller functionality.
    • Combination with Interpreter pattern.
  • 17. Replace Conditional Dispatcher with Command Joshua Kerievsky
    • Motivation
      • Not enough runtime flexibility
      • A bloated body of code
    • Benefits
      • Execute diverse behaviour in a uniform way
      • Dynamically change timing and behaviour of response to requests
      • Trivial Implementation
    • Liability
      • Complicates design