Command Pattern

  • 2,383 views
Uploaded on

Presentation given on Nov 2006 at Melbourne Patterns Group http://htxt.it/jgnK

Presentation given on Nov 2006 at Melbourne Patterns Group http://htxt.it/jgnK

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,383
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
42
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 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