Command Pattern When Actions Speak Louder Than Words.

Slides:



Advertisements
Similar presentations
Cinnamon Cove Computer Club UPDATING ACTIVE HOME.
Advertisements

Command Explained. Intent Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests,
This symbol is used to; Start a flow-chart; Stop a singe flow-chart (or all flow charts in that program); Mark the Start of a Sub-Routine (a separate.
Template, Command, Iterator and Composite CSE 111 5/9/20151Copyright W. Howden.
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.
RIWeb. Getting Started with Research Insight Research insight is an interface provided by S&P which allows Data Access Financial statements Information.
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.
Spring 2010ACS-3913 Ron McFadyen1 Command The complex remote control (many pairs of buttons; null command) Undo … pages 216+ Macro … pages 224+
Feb Ron McFadyen1 Adapter An adapter converts the interface of a class into another interface the client expects. An adapter lets classes work.
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.
Memory Management, File Systems, I/O How Multiprogramming Issues Mesh ECEN 5043 Software Engineering of Multiprogram Systems University of Colorado, Boulder.
March Ron McFadyen1 Singleton pattern Singleton is designed to restrict instantiation of a class to one (or a few) objects. Useful when exactly.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
MONDAYS 10:00-12:00, 14:00-17:00 THURSDAYS 14:00-16:00 FRIDAYS 9:00-12:00 Mark Neil - Microprocessor Course 1 Microprocessor Experiment A6.
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
Recovery-Oriented Computing User Study Training Materials October 2003.
CS 210 Introduction to Design Patterns September 28 th, 2006.
1 Vrijendra Gokhale, Bernard Menezes K. R. School of Information Technology IIT Bombay User Interfaces for Jini Services The Jini Pattern Language Workshop.
CS 415 N-Tier Application Development By Umair Ashraf June 21,2013 National University of Computer and Emerging Sciences Lecture # 2 Introduction to Design.
Oracle Data Integrator Workflow Management: The Packages.
Behavioral Pattern: Command C h a p t e r 5 – P a g e 139 There are times when the need arises to issue a request to an object without knowing anything.
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.
1 Command Design Pattern Rick Mercer and Rice University.
DLP LCD PANEL Programming
Lexi case study (Part 2) Presentation by Matt Deckard.
CS 210 Introduction to Design Patterns September 26 th, 2006.
1 Command Design Pattern Rick Mercer. Command Design Pattern The Command Pattern encapsulates a request as an object, thereby letting you queue commands,
HFOOAD Chapter 3 Change: the constant in software development.
Building Systems Integration Simple Integration with Universal Remote Control.
Structural Design Patterns
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Command Pattern.
Computer Science 313 – Advanced Programming Topics.
CS 210 Review Session October 5 th, Head First Design Patterns Chapter 4 Factory Pattern.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
Working “Control any electrical device with your T.V remote(any brand)” wizardelectronics.weebly.com.
User Interface – Switch Panel 6 Gang Switch Panel Configuration guide RS485 Terminal Fixing hole Bayonet Front ViewBack View.
Mr. Fleming. D.4 Explain the relationship among voltage, current and resistance in a simple series circuit.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
I Like Ike I have always found that plans are useless, but planning is indispensable.
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.
Virtual University - Human Computer Interaction 1 © Imran Hussain | UMT Imran Hussain University of Management and Technology (UMT) Lecture 36 Behavior.
Third International Workshop on Networked Appliance 2001 SONA: Applying Mobile Agent to Networked Appliance Control S.Aoki, S.Makino, T.Okoshi J.Nakazawa.
The Command Pattern SE-2811 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.
 What is it?  What are the benefits?  How does it work? Content.
Command Pattern Encapsulation Invocation. One size fits all.
An operating system (OS) is a collection of system programs that together control the operation of a computer system.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Programming with Patterns Jeremy Cronan Alliance Safety Council
Turning method call into an object
Behavioral Design Patterns
Singleton Pattern Command Pattern
Decorator Design Pattern
Command Pattern.
Programming Design Patterns
Command Pattern 1.
Command Design Pattern
Behavioral and Structural Patterns
PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp
12. Command Pattern SE2811 Software Component Design
The Command Design Pattern
Software Engineering and Architecture
Presentation transcript:

Command Pattern When Actions Speak Louder Than Words

Programmable Remote  Example in book  On/off for seven devices  Single “Undo” button referring to the last button pushed  Can control a wide variety of devices from lights to TVs to other appliances  Difference devices support different operations  Many are on/off  setTemperature(), circulate(), selectChannel(), etc.  Example in book  On/off for seven devices  Single “Undo” button referring to the last button pushed  Can control a wide variety of devices from lights to TVs to other appliances  Difference devices support different operations  Many are on/off  setTemperature(), circulate(), selectChannel(), etc.

Goals of a Good design For This Situation  Separate the remote’s ability to execute a command from the variety of operations and devices that can be supported.  What varies?  Devices and operations  What Stays the same?  The structure of the remote control  Separate the remote’s ability to execute a command from the variety of operations and devices that can be supported.  What varies?  Devices and operations  What Stays the same?  The structure of the remote control

Four Parts of our Design  The actions that we want each button to cause (Command)  Someone to set up those actions (Client)  The remote control to execute the actions (Invoker)  The device affected by the action (Receiver)  The actions that we want each button to cause (Command)  Someone to set up those actions (Client)  The remote control to execute the actions (Invoker)  The device affected by the action (Receiver)

Command Pattern ClientInvoker setCommand() > Command execute() undo() Receiver action() ConcreteCommand execute() undo() public void execute() { receiver.action() }

Command  There are a variety of commands, but we want the remote to treat them all the same  Need Command interface (with an execute() method)  Need Concrete Commands for each operation we will support  Concrete Commands pair the operation with the device it will affect - “light On” paired with a specific light in the house.  There are a variety of commands, but we want the remote to treat them all the same  Need Command interface (with an execute() method)  Need Concrete Commands for each operation we will support  Concrete Commands pair the operation with the device it will affect - “light On” paired with a specific light in the house.

Receiver  The object the command should affect

Invoker  Executes the Commands  Possibly at a later time  Executes the Commands  Possibly at a later time

Let’s Look at the Code  Command.SimpleRemote  Command.Remote  Find  Devices  Concrete Commands  Remote Control  Client  Command.SimpleRemote  Command.Remote  Find  Devices  Concrete Commands  Remote Control  Client

What about that Undo Button?  Add undo() to the Command interface  Each ConcreteCommand must know how to undo the action it executed  Make Remote remember the last command executed and call it’s undo method for the undo button.  Add undo() to the Command interface  Each ConcreteCommand must know how to undo the action it executed  Make Remote remember the last command executed and call it’s undo method for the undo button.

Let’s Look at the code  How does remote remember previously executed command?  Undo for  Lights - simple (does light off need the hardcoded previous value?)  Dimmer - ask device for state before execution  Ceiling fan - see any duplication? How could we eliminate it?  How does remote remember previously executed command?  Undo for  Lights - simple (does light off need the hardcoded previous value?)  Dimmer - ask device for state before execution  Ceiling fan - see any duplication? How could we eliminate it?

Macro Commands  Can make a Concrete Command (subclass of Command) that contains a list of commands  Commands can be given at construction, or set up via method calls  Execute method calls the execute method on each of the commands in the list  How could we use this to give a good progress indicator?  Can make a Concrete Command (subclass of Command) that contains a list of commands  Commands can be given at construction, or set up via method calls  Execute method calls the execute method on each of the commands in the list  How could we use this to give a good progress indicator?

Other uses of command  Queuing requests  Can allocate commands to various threads for processing to load balance between threads/processors  Logging requests (audit trail)  Just have to save the command objects as they execute.  If something goes wrong, we can read the log and re-create the sequence of commands (so no data is lost).  Can also back out changes that cause troubles  Queuing requests  Can allocate commands to various threads for processing to load balance between threads/processors  Logging requests (audit trail)  Just have to save the command objects as they execute.  If something goes wrong, we can read the log and re-create the sequence of commands (so no data is lost).  Can also back out changes that cause troubles

Starting Lab TODAY!