1 / 10

CS 210

CS 210. Introduction to Design Patterns September 26 th , 2006. Head First Design Patterns. Chapter 6 Command Pattern Encapsulating Invocation. Motivating problem description. Build a remote that will control variety of home devices

raven-booth
Download Presentation

CS 210

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 210 Introduction to Design Patterns September 26th, 2006

  2. Head First Design Patterns Chapter 6 Command Pattern Encapsulating Invocation

  3. Motivating problem description • Build a remote that will control variety of home devices • Sample devices: lights, stereo, TV, ceiling light, thermostat, sprinkler, hot tub, garden light, ceiling fan, garage door

  4. Order orderUp takeOrder Make Burger & Shake Introducing the command pattern – Diner example createOder() Burger & Shake Order Slip Customer takeOder() Waiter orderUp() Command Cook make_X()

  5. execute() execute() Create Command Object setCommand action1 action2 Introducing the command pattern creatCommandObject() Command Client setCommand() Invoker execute() Command Receiver action_X()

  6. action() Receiver RemoteSlot execute() execute() execute() LightOnCommand GarageDoorOpen StereoOff Command Pattern for home automation An encapsulated Request execute(){ receiver.action() } Invoker Command

  7. Simple Remote Control • Eclipse example

  8. 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.

  9. Client Invoker Receiver <<Interface>> Command setCommand() action() execute() undo() Command Pattern Class Diagram ConcreteCommand execute() undo()

  10. Light <<Interface>> Command execute() undo() LightOnCommand LightOffCommand execute() undo() execute() undo() Command Pattern Class Diagram for Home automation RemoteControl RemoteLoader onCommands offCommands setCommand() onButtonPushed() offButtonPushed() on() off()

More Related