Command Design Pattern

Slides:



Advertisements
Similar presentations
CSE 4939 Alex Riordan Brian Pruitt-Goddard Remote Unit Testing.
Advertisements

Computer Science 313 – Advanced Programming Topics.
Command Pattern 1. Intent Encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log request,
March Ron McFadyen1 Command The command pattern encapsulates a request or unit of work into an object. An invoker will ask a concrete command.
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.
CS 501: Software Engineering Fall 2000 Lecture 16 System Architecture III Distributed Objects.
Object Oriented Software Development Class diagrams: Towards implementation OOSAD Booklet Chapter 4 Seminar: Week 4 Brian Farrimond.
Command Pattern Chihung Liao Cynthia Jiang. Waiter Order Execute() Hamburger Execute() Hot Dogs Execute() Fries Execute() Cook Make Food()
Command Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Command Pattern When Actions Speak Louder Than Words.
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
Chapter 13 Starting Design: Logical Architecture and UML Package Diagrams.
BCS 2143 Introduction to Object Oriented and Software Development.
Model View Controller (MVC) Rick Mercer with a wide variety of others 1.
CS 210 Introduction to Design Patterns September 28 th, 2006.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
Course Overview & Topics CSc 335: Object-Oriented Programming and Design © Rick Mercer 1.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VII Observer, Command, and Memento.
1 Command Design Pattern Rick Mercer and Rice University.
Lexi case study (Part 2) Presentation by Matt Deckard.
Client Call Back Client Call Back is useful for multiple clients to keep up to date about changes on the server Example: One auction server and several.
CS 210 Introduction to Design Patterns September 26 th, 2006.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
1 Command Design Pattern Rick Mercer. Command Design Pattern The Command Pattern encapsulates a request as an object, thereby letting you queue commands,
Model View Controller (MVC) Bigger than a Pattern: It’s an Architecture Rick Mercer with help from many others 1.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Command Pattern.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
CS 501: Software Engineering Fall 1999 Lecture 12 System Architecture III Distributed Objects.
Model View Controller (MVC) Bigger than a Pattern: It’s an Architecture Rick Mercer with help from many of others 1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
CS 151: Object-Oriented Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Intro to Web Services Dr. John P. Abraham UTPA. What are Web Services? Applications execute across multiple computers on a network.  The machine on which.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Model View Controller (MVC) an architecture Rick Mercer with help from many of others 1.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
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.
Command Pattern Encapsulation Invocation. One size fits all.
1 CS 501 Spring 2002 CS 501: Software Engineering Lecture 15 System Architecture III.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Distributed Web Systems Distributed Objects and Remote Method Invocation Lecturer Department University.
Chapter 32 JavaBeans and Bean Events
GUIs and Events Rick Mercer.
Principles of Software Development
Chapter 36 JavaBeans and Bean Events
Behavioral Design Patterns
Remote Method Invocation
Object Oriented Concepts -I
Lecture 2 of Computer Science II
Chapter 9.3 Security Access Control
Command Pattern.
Programming Design Patterns
Doug Jeffries CS490 Design Patterns May 1, 2003
Command Pattern 1.
Chapter 19: Interfaces and Components
INFS 6225 – Object-Oriented Systems Analysis & Design
Chapter 12 Collections.
Introduction to Unified Modeling Language (UML)
Starting Design: Logical Architecture and UML Package Diagrams
Chapter 7 –Implementation Issues
Review CSE116 2/21/2019 B.Ramamurthy.
Chapter 12 Collections.
The Command Design Pattern
Interfaces and Components
Message Passing Systems Version 2
Software Engineering and Architecture
Message Passing Systems
Presentation transcript:

Command Design Pattern Rick Mercer

Command Design Pattern The Command Pattern encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue commands, send commands over the internet like in a networked game, and support undo and redo…. http://en.wikipedia.org/wiki/Command_pattern

Example for Heads First Note: RemoteLoader loads commands into slots of the remote control

Command Pattern One object can send messages to other objects without knowing anything about the actual operation or the type of object Polymorphism lets us encapsulate a request for services as an object Establish a method signature name as an interface Vary the algorithms in the called methods

Java Examples Sun used the Command pattern to improve the event model in Java 1.1 one example method signature: public void actionPerfomed(ActionEvent e) JButtons and JTextFields send actionPerformed messages to "command" objects (the listeners) without knowing what will happen Event generators — buttons, text fields, mouse — have listener objects (actually a List of listener objects)

Uses The Command object can also be used when you need to tell the program to execute the command later. In such cases, you are saving commands as objects to be executed later You could also sending command objects over the network (in new project) or save them in a collection class such as a Stack for undo/redo operations

Example we saw before was Command Make 3 command classes Log instances by writing the objects to a file See SaveWorkCommands .java in the Eclipse project CommandPattern (command.zip) Like RemoteLoader in HFSP or Client in gen. form Read the objects later and execute them See ExecuteSavedCommands .java in the Eclipse project CommandPattern (command.zip) Like Light on HFSP or Receiver in gen. form

A UML View of the Sample

See code demos page for CommandPattern.zip import java.io.Serializable; // Command design pattern - Decoupling producer from consumer. public interface WorkCommand { void execute(); } class DomesticEngineer implements WorkCommand, Serializable { public void execute() { System.out.println("Take out the trash."); class Politician implements WorkCommand, Serializable { System.out.println("Take money from the rich, take votes from the poor."); class Programmer implements WorkCommand, Serializable { System.out.println("Sell the bugs, charge extra for the fixes."); See code demos page for CommandPattern.zip

Summary The Command design pattern encapsulates the concept of a command into an object A command object could be sent across a network to be executed elsewhere or it could be saved as a log of operations

References [Adelson and Soloway] B. Adelson and E. Soloway. The Role of Domain Experience in Software Design. IEEE Trans. on Software Engineering, V SE-11, N 11, 1985, pp. 1351-1360. [Linn and Clancy] M. Linn and M. Clancy, The Case for Case Studies of Programming Problems. Communications of the ACM V 35 N 3, March 1992, pp. 121-132. [Soloway and Ehrlich] E. Soloway and K. Ehrlich, Empirical Studies of Programming Knowledge, IEEE Transactions on Software Engineering V SE-10, N 5, September 1984. [Curtis] B. Curtis, Cognitive Issues in Reusing Software Artifacts. In Software Reusability, V II. ed. T. Biggerstaff and A. Perlis, Addison Wesley 1989, pp. 269-287. [Sierra and Bates ], Heads First Design Patterns http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/command.htm