Command Pattern Encapsulation Invocation. One size fits all.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Command Explained. Intent Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests,
Remote Method Invocation
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.
Algorithm Programming Concurrent Programming in Java Bar-Ilan University תשס"ח Moshe Fresko.
Fibonacci Numbers A simple example of program design.
1 Pattern Games CS : Software Design Winter /T9.
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.
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.
How Does Remote Method Invocation Work? –Systems that use RMI for communication typically are divided into two categories: clients and servers. A server.
March Ron McFadyen1 Singleton pattern Singleton is designed to restrict instantiation of a class to one (or a few) objects. Useful when exactly.
Command Pattern When Actions Speak Louder Than Words.
CS 350 – Software Design Command Object Remote Control Object.
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.
Programming Progamz pls. Importance VERY IMPORTANT.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
CS 415 N-Tier Application Development By Umair Ashraf June 21,2013 National University of Computer and Emerging Sciences Lecture # 2 Introduction to Design.
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.
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
1 Command Design Pattern Rick Mercer and Rice University.
Lexi case study (Part 2) Presentation by Matt Deckard.
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,
Copyright 2012 & 2015 – Noah Mendelsohn A Brief Intro to the RPC Project Framework Noah Mendelsohn Tufts University
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.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
STATE PATTERN Presented by Bharavi Mishra Bharavi Mishraise
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.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
I Like Ike I have always found that plans are useless, but planning is indispensable.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
COME 339 WEEK 1. Example: The Course Class 2 TestCourceRunCourse.
Methods.
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.
1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
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.
Errors, GUIs, and Patterns Dr. Doug Twitchell August 30, 2005.
Overview of Behavioral Patterns ©SoftMoore ConsultingSlide 1.
Staples are our staple Building upon our solution.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
GC211 Data structure Lecture 3 Sara Alhajjam.
using System; namespace Demo01 { class Program
Façade Pattern:.
Chapter 6 Queue.
Remote Method Invocation
Command Pattern.
Programming Design Patterns
Doug Jeffries CS490 Design Patterns May 1, 2003
Command Pattern 1.
Command Design Pattern
Interfaces and an Array List
Chapter 6 Queue.
PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp
Composite describes a group of objects that is treated the same way as a single instance of the same type of object. composition of one-or-more similar.
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Chapter 6 Queue.
The Command Design Pattern
Presentation transcript:

Command Pattern Encapsulation Invocation

One size fits all

Vender Classes

Intro to Command Pattern

Interaction in detail

Encapsulation An order Slip encapsulates a request to prepare a meal. An order Slip encapsulates a request to prepare a meal. The waitress's job is to take order Slips and invoke the orderUp() method on them. The waitress's job is to take order Slips and invoke the orderUp() method on them. The Cook has the knowledge required to prepare the meal. The Cook has the knowledge required to prepare the meal.

API interface??

From Dinner to Command Pattern

Our first command object public interface Command { public void execute(); } Implementing Command to turn light on public class LightOnCommand implements Command { public LigthOnCommand(Light light) { this.light = light; } public void execute(){ light.on(); } } Light on() off()

Using Command object public class SimpleRemoteControl { Command slot; public SimpleRemoteControl() { } public void setCommand(Command command) { slot = command; } public void buttonWasPresses() { slot.execute(); }

Creating a simple test public class RemoteControlTest { public static void main(String[] args) { SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); GarageDoor garageDoor = new GarageDoor(); LightOnCommand lightOn = new LightOnCommand(light); GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor); remote.setCommand(lightOn); remote.buttonWasPressed(); remote.setCommand(garageOpen); remote.buttonWasPressed(); } }

Command Pattern Defined 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.

public class RemoteControl { Command[] onCommands; Command[] offCommands; public RemoteControl() { onCommands = new Command[7]; offCommands = new Command[7]; Command noCommand = new NoCommand(); for (int i = 0; i < 7; i++) { onCommands[i] = noCommand; offCommands[i] = noCommand;}} public void setCommand(int slot, Command onCommand, Command offCommand) { onCommands[slot] = onCommand; offCommands[slot] = offCommand;} public void onButtonWasPushed(int slot) { onCommands[slot].execute();} public void offButtonWasPushed(int slot) { offCommands[slot].execute();} }}