Download presentation
Presentation is loading. Please wait.
Published byGiles Tate Modified over 8 years ago
1
CS 210 Introduction to Design Patterns September 26 th, 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
Introducing the command pattern – Diner example Burger & Shake Order takeOrderorderUp Make Burger & Shake createOder() takeOder() orderUp() make_X()
5
Introducing the command pattern Create Command Object execute()setCommandexecute() action1 action2 creatCommandObject() setCommand() execute() action_X()
6
Command Pattern for home automation action() execute(){ receiver.action() } execute() An encapsulated Request Invoker
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
Command Pattern Class Diagram ClientInvoker setCommand() > Command execute() undo() Receiver action() ConcreteCommand execute() undo()
10
Command Pattern Class Diagram for Home automation RemoteLoader RemoteControl onCommands offCommands setCommand() onButtonPushed() offButtonPushed() > Command execute() undo() Light on() off() LightOnCommand execute() undo() LightOffCommand execute() undo()
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.