Presentation is loading. Please wait.

Presentation is loading. Please wait.

Feb 200692.3913 Ron McFadyen1 Adapter An adapter converts the interface of a class into another interface the client expects. An adapter lets classes work.

Similar presentations


Presentation on theme: "Feb 200692.3913 Ron McFadyen1 Adapter An adapter converts the interface of a class into another interface the client expects. An adapter lets classes work."— Presentation transcript:

1 Feb 200692.3913 Ron McFadyen1 Adapter An adapter converts the interface of a class into another interface the client expects. An adapter lets classes work together that couldn't otherwise (due to incompatible interfaces). Adaptee specificRequest() Adapter request() Target request() Client

2 Feb 200692.3913 Ron McFadyen2 Adapter: Textbook example p.248-51 Adapter: The object that adapts the adaptee to the adapter. In this example, the EnumeratorAdapter adapts the Enumeration interface to the Iterator interface. Adaptee: the object not supporting the target interface. The legacy code in this example uses the Enumeration interface. Target: the interface used by the client. In this example, the client is written to use the Iterator interface. > Iterator Enumeration Adapter > Enumeration Client Adapter adapteradaptee target hasMoreElements() nextElement() hasNext() next() remove() hasNext() next() remove()

3 Feb 200692.3913 Ron McFadyen3 Adapter example sequence diagram :Enumeration:Client hasNext() hasMoreElements() next() nextElement() :EnumerationAdapter remove()

4 Feb 200692.3913 Ron McFadyen4 Factory Method We have two parallel hierarchies, of products and factories. The factory subclasses contain the implementation of the create method – the factory subclasses know what kind of product in the other hierarchy to create. Product Concrete Product Concrete Factory Client Factory Method adaptee factorymethod() other() Factory factorymethod() factoryMethod() is implemented in the creator subclasses product concrete product concrete creator creator

5 Feb 200692.3913 Ron McFadyen5 Factory Method Text example has Pizza Stores creating Pizzas. Each Pizza Store knows what it creates and how to do it. Pizza NYStyleCheezePizza NYPizzaStore Client Factory Method adaptee createPizza() orderPizza() PizzaStore createPizza() createPizza() is the factory method and is implemented in the creator subclasses product concrete product concrete creator creator NYStyleVeggiePizza

6 Feb 200692.3913 Ron McFadyen6 Factory Method :Client orderPizza(veggie)createPizza() create() :NYVeggiePizza :NYPizzaStore

7 Feb 200692.3913 Ron McFadyen7 Command The command pattern encapsulates a request or unit of work into an object > Command Concrete Command Receiver Invoker Command Concrete commandreceiver command action1() action2() execute() setCommand() invoker

8 Feb 200692.3913 Ron McFadyen8 Command > Command lightOn Command Light Remote control Command Concrete commandreceiver command on() off() execute() setCommand() invoker Invoker: asks the command to carry out its purpose Command: the interface for command objects (Holub’s example includes undo() too) Concrete command: an object implementing the command interface – it will ask some receiver to perform certain actions. Receiver: the object that carries out the actions lightOff Command execute() Concrete command

9 Feb 200692.3913 Ron McFadyen9 Command :Light:RemoteControl execute() lightOn() execute() lightOff() :LightOn Command :LightOff Command


Download ppt "Feb 200692.3913 Ron McFadyen1 Adapter An adapter converts the interface of a class into another interface the client expects. An adapter lets classes work."

Similar presentations


Ads by Google