The Command Pattern SE-2811 Dr. Mark L. Hornick 1.

Slides:



Advertisements
Similar presentations
© SERG Dependable Software Systems (OO Protocol Testing) Dependable Software Systems Testing the Protocols of Classes in Object-Oriented Programs Material.
Advertisements

SE2811 Week 8 Monday (last drop day) The Command Pattern Lambda Expressions SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr.
Command Explained. Intent Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests,
SE2811 Week 7, Class 2 The Gang of Four and more … Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder.
Computer Science 313 – Advanced Programming Topics.
Week 8, Class 3: Model-View-Controller Model-View-Controller Why? What? How? Example: Barnyard Simon for the Web Question: Where should we use the command.
March Ron McFadyen1 Command The command pattern encapsulates a request or unit of work into an object. An invoker will ask a concrete command.
Software Design & Documentation – Design Pattern: Command Design Pattern: Command Christopher Lacey September 15, 2003.
Copyright © 1995 –2004 Active Frameworks Inc. - All Rights Reserved - V2.0Behavioral Patterns - Page L8-1 PS95&96-MEF-L15-1 Dr. M.E. Fayad Creationa l.
Command Pattern Chihung Liao Cynthia Jiang. Waiter Order Execute() Hamburger Execute() Hot Dogs Execute() Fries Execute() Cook Make Food()
Spring 2010ACS-3913 Ron McFadyen1 Command The command pattern encapsulates a request or unit of work into an object. An invoker will ask a concrete command.
Command Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Command Pattern When Actions Speak Louder Than Words.
Data Structures Data structures permit the storage of related data for use in your program. –Arrays.
BY VEDASHREE GOVINDA GOWDA
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
State Machines State diagrams SE-2030 Dr. Rob Hasker 1 Based on slides written by Dr. Mark L. Hornick Used with permission.
© 2008 Autodesk Recap of UI, Sketch and Part Modeling Answers to common issues Fusion FIRST training 2011.
Week 5, Day 3: Observer Today Reducing coupling with the Observer The Observer pattern in Java APIs Posting events to a UI worker thread SE-2811 Slide.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
CSE 1301 Lecture 11 Object Oriented Programming Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
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.
The Adapter Pattern SE-2811 Dr. Mark L. Hornick 1.
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.
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
The Façade Pattern SE-2811 Dr. Mark L. Hornick 1.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Command Pattern.
Class and Sequence diagrams UML notation SE-2030 Dr. Mark L. Hornick 1.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Reusing threads.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
Chapter Three The UNIX Editors.
SE-2840 Dr. Mark L. Hornick1 Servlet Threads and Sessions.
UML for UI Plugin Framework Example Elijah Kerry National Instruments ni.com/largeapps.
UML Class Diagram notation Indicating relationships between classes SE-2030 Dr. Mark L. Hornick 1.
Interface Patterns. Adapter Provides the interface a client expects, using the services of a class with a different interface Note Avoid using object.
Elaboration Iteration 3 – Part 3 - Persistence Framework -
Operating System Concepts Three User Interfaces Command-line Job-Control Language (JCL) Graphical User Interface (GUI)
State Machines State diagrams SE-2030 Dr. Mark L. Hornick 1.
Week 7, Day 3 Half-Exam 2 A New Pattern SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Behavioural Patterns GoF pg Iterator GoF pg. 257 – 271 Memento GoF pg By: Dan Sibbernsen.
Week 9, Day 2 Object-oriented Design Acknowledgement: These slides by Dr. Hasker SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
CSE 432: Thanks for the memory leaks, Pushme-Pullyu, and Command Summary of “Thanks for the Memory Leaks” “Left-over” design forces from Type Laundering.
Week 7, Class 1: The Command Pattern (cont.) Get Ready for Poll Everywhere Labs 2 & 3 returned Lab 7 due this evening at 11pm Quiz tomorrow at start of.
Model-View-Controller A Design Pattern SE-2030 Dr. Rob Hasker 1 Based on slides written by Dr. Mark L. Hornick Used with permission.
Week 10, Day 3 Review for the quarter SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
High Level Design Use Case Textual Analysis SE-2030 Dr. Mark L. Hornick 1.
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.
Week 9, Day 1 Proxy SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
SE-1020 Dr. Mark L. Hornick 1 Creating Graphical User Interfaces.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Turning method call into an object
Section 13 - Integrating with Third Party Tools
Cross Platform Development using Software Matrix
Singleton Pattern Command Pattern
Note 11 Command Pattern SE2811 Software Component Design
Command Pattern.
Programming Design Patterns
Doug Jeffries CS490 Design Patterns May 1, 2003
Model-View-Controller
12. Command Pattern SE2811 Software Component Design
Week 7, Class 1: The Command Pattern (cont.)
PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp
Windowing Push-Pull Systems
12. Command Pattern SE2811 Software Component Design
The Command Design Pattern
Software Engineering and Architecture
Presentation transcript:

The Command Pattern SE-2811 Dr. Mark L. Hornick 1

Consider the following application SE-2811 Dr. Mark L. Hornick 2

Command Pattern Problem: We want [a UI] to issue requests to objects without knowing anything… About the request [command] being made. About the receiver [executor] of the request. Solution: Represent the request [command] as an object. The request [command] can then be stored and passed around like other objects.

Example Configurable GUI represents actions as Menus and menu items Push buttons These objects carry out a request in response to user input, but The Toolkit cannot implement the request. Application that uses the toolkit knows what to do. The Toolkit designers do not know who will receive the request the operation that will be carried out as a result.

The Different Players Invoker: UI via Invoker helper Command: CarStartCmd Receiver: Car Execute: startEngine() Invoker: MenuItem Command: PasteCommand, Open Command Receiver: Document, Application Execute(): Calls paste action on the document Calls open action on an application. X10 ExampleMS-Word Example

Generic Command Pattern UML Class Diagram (Note: from GOF book – UML associations inconsistent w.r.t. current UML standard) Aggregation incorrect Non-std association

SE-2811 Dr. Mark L. Hornick 7 Command Pattern Example

Sequence of Events The client is responsible for creating concrete Command objects The Command objects consists of a set of actions on a Receiver Which means the Command calls various Receiver methods The Receiver is also stored in the Command object The client calls an invocation method on an Invoker object and passes it the Command object, where it gets stored until it is needed. The Invoker may execute the Command immediately queue the Command for execution on another thread (perhaps at a later time) wait until the client requests for the Command to be executed Execution of a Command means calling the Command’s execute() method This results in the actions being invoked on the Receiver.

SE-2811 Dr. Mark L. Hornick 9 Implementing “Undo”

UNDO: Sequence of Events The client calls the invocation method on an Invoker object and passes it the Command object, To implement UNDO, the Invoker: Stores each command it executes on a STACK When UNDO is invoked, the commands are popped off the stack and un-executed Un-Execution of a Command means calling the Command’s unexecute() method This results in the previous actions being reversed on the Receiver. It may not be possible to reverse all actions