1 Command Design Pattern Rick Mercer and Rice University.

Slides:



Advertisements
Similar presentations
Remote Method Invocation
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 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
March Ron McFadyen1 Command The command pattern encapsulates a request or unit of work into an object. An invoker will ask a concrete command.
Real-Time Authentication Using Digital Signature Schema Marissa Hollingsworth BOISECRYPT ‘09.
Introduction To System Analysis and Design
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()
Improving UML Class Diagrams using Design Patterns Semantics Shahar Maoz Work in Progress.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
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.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
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.
Introduction To System Analysis and Design
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
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.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology.
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.
Facade Introduction. Intent Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the.
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.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Command Pattern.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Title Carolina First Steering Committee October 9, 2010 Online Voting System Design Yinpeng Li and Tian Cao May 3, 2011.
CS 501: Software Engineering Fall 1999 Lecture 12 System Architecture III Distributed Objects.
Field Trip #28 Securing a VNC Connection with Java By Keith Lynn.
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.
Builder An Object Creational Pattern Tim Rice CSPP51023 March 2, 2010.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
PRESENTATION 2 Sri Raguraman CIS 895 Kansas State University.
CS 151: Object-Oriented Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Chapter 19: Interfaces and Components [Arlow and Neustadt, 2005] University of Nevada, Reno Department of Computer Science & Engineering.
The Mediator Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
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.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
More Patterns CS 124. More Basic Patterns Patterns you’ve already seen (without knowing it) Observer / Listener Wrapper Composite Decorator / Filter Patterns.
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 Pattern Encapsulation Invocation. One size fits all.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Chapter 32 JavaBeans and Bean Events
Chapter 36 JavaBeans and Bean Events
Behavioral Design Patterns
Remote Method Invocation
Command Pattern.
Programming Design Patterns
Doug Jeffries CS490 Design Patterns May 1, 2003
Command Pattern 1.
Command Design Pattern
Starting Design: Logical Architecture and UML Package Diagrams
The Command Design Pattern
Software Engineering and Architecture
Presentation transcript:

1 Command Design Pattern Rick Mercer and Rice University

Command Design Pattern The Command Pattern encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log requests, and support undoable operations. 2

General Form 3

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

5 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

6 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 Vector of listener objects)

7 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

8 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

9 A UML View of the Sample

10 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 { public void execute() { System.out.println("Take money from the rich, take votes from the poor."); } class Programmer implements WorkCommand, Serializable { public void execute() { System.out.println("Sell the bugs, charge extra for the fixes."); }

11 Code Demo Need these three files WorkCommand.java CommandClient.java CommandServer.java

12 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

13 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 [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 [Soloway and Ehrlich] E. Soloway and K. Ehrlich, Empirical Studies of Programming Knowledge, IEEE Transactions on Software Engineering V SE-10, N 5, September [Curtis] B. Curtis, Cognitive Issues in Reusing Software Artifacts. In Software Reusability, V II. ed. T. Biggerstaff and A. Perlis, Addison Wesley 1989, pp [Sierra and Bates ], Heads First Design Patterns d.htm