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.

Slides:



Advertisements
Similar presentations
Winter 2007ACS-3913 Ron McFadyen1 Duck Example Consider the text example (up to page 6). Each type of duck is a subclass of Duck Most subclasses implement.
Advertisements

Chapter 4: The Factory Pattern. Consider the Following Code Fragment Duck duck; if (picnic) { duck = new MallardDuck(); } else if (hunting) { duck = new.
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.
Feb Ron McFadyen1 Iterator Pattern Recall Generic UML class diagram The iterator is used to access the elements of some aggregate. The aggregate.
Informatics 122 Software Design II Lecture 5 Emily Navarro Duplication of course material for any commercial purpose without the explicit written permission.
Feb Ron McFadyen1 Factory Method Iterator Example : Java collection classes represent an example of the Factory Method design pattern. The.
Prototype Pattern Creational Pattern Specify the kinds of objects to create using a prototypical instance, and create new objects by copy this prototype.
Spring 2010ACS-3913 Ron McFadyen1 Command The complex remote control (many pairs of buttons; null command) Undo … pages 216+ Macro … pages 224+
Fall 2009ACS Ron McFadyen1 The context maintains an instance of a concrete state subclass State Pattern Each subclass (concrete state) implements.
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.
Feb Ron McFadyen1 Iterator Pattern Generic UML class diagram The iterator is used to access the elements of some aggregate. The aggregate interface.
March Ron McFadyen1 Adapter An adapter converts the interface of a class into another interface clients expect. An adapter lets classes work.
March Ron McFadyen1 Singleton pattern Singleton is designed to restrict instantiation of a class to one (or a few) objects. Useful when exactly.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Spring 2010ACS-3913 Ron McFadyen1 Duck Example Consider the text example (up to page 6). Each type of duck is a subclass of Duck Most subclasses implement.
Command Pattern When Actions Speak Louder Than Words.
+ Informatics 122 Software Design II Lecture 8 Emily Navarro Duplication of course material for any commercial purpose without the explicit written permission.
Design Patterns Ric Holt & Sarah Nadi U Waterloo, March 2010.
Design Patterns.
ADAPTER PATTERN BY Sravanthi Karumanchi. Structure Pattern Structure patterns are concerned with how classes and objects are composed to form large structures.
CS 210 Introduction to Design Patterns September 28 th, 2006.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Abstract Factory Abstract Factory using Factory Method.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
CS 210 Introduction to Design Patterns September 26 th, 2006.
Design Patterns Façade, Singleton, and Factory Methods Team Good Vibrations (1)
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
By Shishir Kumar Contact:
Structural Design Patterns
CS 210 Review Session October 5 th, Head First Design Patterns Chapter 4 Factory Pattern.
Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method Pattern.
Computer Science 209 The Factory Pattern. Collections and Iterators List list1 = new ArrayList (); List list2 = new LinkedList (); Set set1 = new HashSet.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
Chapter 7: The Adapter Pattern. Object Oriented Adapters Suppose that you have existing software. You have outsourced some of your work and there is a.
Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
CS212: Object Oriented Analysis and Design Lecture 38: Design Pattern-II.
Adapter and Façade Patterns By Wode Ni and Leonard Bacon-Shone.
The Factory Pattern Sanjay Yadav (ISE ).
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:
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
S.Ducasse Stéphane Ducasse 1 Adapter.
CS 210 Adapter Pattern October 17 th, Adapters in real life Page 236 – Head First Design Patterns.
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.
Command Pattern Encapsulation Invocation. One size fits all.
SE 461 Software Patterns. FACTORY METHOD PATTERN.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Factory Method Pattern. Admin SCPI Patner Day Feb. 21 Lunch count Presentation (4-8 min.) Practice on Feb. 16. Morning availablity on Feb21 Brief overview.
Chapter 10 Design Patterns.
Structural Patterns Structural patterns control the relationships between large portions of your applications. Structural patterns affect applications.
Design Patterns with C# (and Food!)
Adapter, Fascade, and More
Command Pattern.
Programming Design Patterns
Command Pattern 1.
Abstract Factory Pattern
Behavioral and Structural Patterns
State Design Pattern 1.
Adapter Pattern 1.
Object Oriented Design Patterns - Structural Patterns
Structural Patterns: Adapter and Bridge
Adapter Design Pattern
The Adapter Pattern.
Software Design Lecture : 34.
Presentation transcript:

Feb 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

Feb Ron McFadyen2 Adapter: Textbook example p 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()

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

Feb 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

Feb 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

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

Feb 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

Feb 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

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