Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.

Slides:



Advertisements
Similar presentations
Chain of Responsibility Pattern Gof pp Yuyang Chen.
Advertisements

Command Explained. Intent Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests,
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Computer Science 313 – Advanced Programming Topics.
Matt Klein 7/2/2009.  Intent  Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.
Command Pattern 1. Intent Encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log request,
Patterns Lecture 2. Singleton Ensure a class only has one instance, and provide a global point of access to it.
Design Patterns In OPM Presented by: Galia Shlezinger Instructors: Prop. Dov Dori, Dr. Iris Berger.
Software Design & Documentation – Design Pattern: Command Design Pattern: Command Christopher Lacey September 15, 2003.
Design Pattern Course Builder Pattern 1 Mahdieh Monzavi AmirKabir University of Technology, Department of Computer Engineering & Information Technology.
Command Pattern Chihung Liao Cynthia Jiang. Waiter Order Execute() Hamburger Execute() Hot Dogs Execute() Fries Execute() Cook Make Food()
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
Prototype Creational Design Pattern By Brian Cavanaugh September 22, 2003 Software, Design and Documentation.
Reuse Activities Selecting Design Patterns and Components
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
BY VEDASHREE GOVINDA GOWDA
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
CS 210 Introduction to Design Patterns September 28 th, 2006.
© Spiros Mancoridis 27/09/ Software Design Topics in Object-Oriented Design Patterns Material drawn from [Gamma95] and [Coplien95] Revised and augmented.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Command. RHS – SOC 2 Executing a command Executing a command appears simple at first, but many details to consider: –Who creates a command? –Who invokes.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VII Observer, Command, and Memento.
Lexi case study (Part 2) Presentation by Matt Deckard.
GoF Sections Design Problems and Design Patterns.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Command Pattern.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
The Factory Method Design Pattern Motivation: Class / Type separation – Abstract class serves as type definition and concrete class provides implementation.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
Prototype pattern Participants Prototype (Graphic) – declared an interface for cloning itself ConcretePrototype (EditBox, Slider) – implements an operation.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Object Oriented Programming
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
Bridge Bridge is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
CS 5150 Software Engineering Lecture 16 Program Design 3.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
Command. RHS – SWC 2 Executing a command Executing a command appears simple at first, but many details to consider: –Who creates a command? –Who invokes.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Abstract Factory Pattern
Factory Method Pattern
Turning method call into an object
Structural Patterns Structural patterns control the relationships between large portions of your applications. Structural patterns affect applications.
Behavioral Design Patterns
Software Design and Architecture
Chapter 3: Using Methods, Classes, and Objects
Abstract Factory Pattern
Intent (Thanks to Jim Fawcett for the slides)
Command Pattern.
Programming Design Patterns
Doug Jeffries CS490 Design Patterns May 1, 2003
Object-Oriented Design
Command Pattern 1.
Design Patterns Satya Puvvada Satya Puvvada.
Jim Fawcett CSE776 – Design Patterns Summer 2003
State Design Pattern 1.
Behavioral Patterns Part-I introduction UNIT-VI
PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp
Mechanisms for improving software reuse
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
BRIDGE PATTERN.
Strategy Design Pattern
Creational Patterns.
The Command Design Pattern
Software Engineering and Architecture
Software Design Lecture 11.
Visitor Pattern Intent
Presentation transcript:

Command Pattern

Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable operations

Motivation l Sometimes have to issue requests without knowing the operation or the receiver l encapsulate request in an object abstract Command class - declares interface for executing operations concrete Command subclasses - specify receiver-action pair receiver – instance variable l decouples object which invokes operation from object with knowledge to perform operation l can replace dynamically =>can have context-sensitive user interface

Applicability l Parameterize objects by an action to perform procedural language - callback function l specify, queue, execute requests at different times Command object - lifetime independent of original request l support undo Execute operation - can store state for reversing effects stored in a history list

l support logging changes log Command objects on disk l structure a system around high-level operations built on primitive operations transaction - encapsulate set of changes to data => can be modelled with Commands

Structure

Participants l Command declares an interface for executing an operation l ConcreteCommand defines a binding between a Receiver object & an action implements Execute by invoking appropriate operations on Receiver l Client creates ConcreteCommand object & sets its receiver l Invoker asks the command to carry out request l Receiver knows how to perform operations associated with carrying out a request

Collaborations l client creates ConcreteCommand object & specifies its receiver l Invoker object - stores ConcreteCommand object l Invoker - issues request by calling Execute on command l ConcreteCommand object - invokes operations on receiver

Consequences l decouples object that invokes operation from the one that knows how to perform it l commands - first class objects => can be manipulated like any other object l can assemble commands into a composite command l easy to add new commands subclassing

Implementation l how intelligent should a command be? one extreme - defines binding between receiver & actions other extreme – implements everything without delegating to receiver command - independent of existing classes no suitable receiver exists command knows its receiver implicitly

l supporting undo & redo must provide way to reverse execution – might need to store state Receiver object arguments for operation any original values in receiver which could be changed by handling request multiple levels of undo & redo - need history list l avoiding error accumulation in undo process l using C++ templates command cannot be undoable & cannot have arguments avoid subclass proliferation

Sample Code l C++ C++ l JAVA JAVA