Upload
osamaalqaise
View
217
Download
0
Embed Size (px)
Citation preview
8/14/2019 Part2 Adapter Pattern
1/16
8/14/2019 Part2 Adapter Pattern
2/16
Structural patternsIn Software Engineering, Structural DesignPatterns are Design Patterns that ease thedesign by identifying a simple way to realizerelationships between entities.AdapterMatch interfaces of different classesBridgeSeparates an objects interface fromits implementationComposite
A tree structure of simple and composite objectsDecoratorAdd responsibilities to objects dynamicallyFacadeA single class that represents an entire subsystemProxy
An object representing another object
http://sourcemaking.com/design_patterns/adapterhttp://sourcemaking.com/design_patterns/bridgehttp://sourcemaking.com/design_patterns/compositehttp://sourcemaking.com/design_patterns/decoratorhttp://sourcemaking.com/design_patterns/facadehttp://sourcemaking.com/design_patterns/proxyhttp://sourcemaking.com/design_patterns/proxyhttp://sourcemaking.com/design_patterns/facadehttp://sourcemaking.com/design_patterns/decoratorhttp://sourcemaking.com/design_patterns/compositehttp://sourcemaking.com/design_patterns/bridgehttp://sourcemaking.com/design_patterns/adapter8/14/2019 Part2 Adapter Pattern
3/16
Creational patternIn software engineering, creational designpatterns are design patterns that deal withobject creation mechanisms, trying to createobjects in a manner suitable to the situation. The
basic form of object creation could result indesign problems or added complexity to thedesign. Creational design patterns solve thisproblem by somehow controlling thisobject creation
8/14/2019 Part2 Adapter Pattern
4/16
Creational pattern
Abstract FactoryCreates an instance of several families of classesBuilderSeparates object construction from its representation
Factory MethodCreates an instance of several derived classesObject PoolAvoid expensive acquisition and release of resources byrecycling objects that are no longer in use
PrototypeA fully initialized instance to be copied or clonedSingletonA class of which only a single instance can exist
http://sourcemaking.com/design_patterns/abstract_factoryhttp://sourcemaking.com/design_patterns/builderhttp://sourcemaking.com/design_patterns/factory_methodhttp://sourcemaking.com/design_patterns/object_poolhttp://sourcemaking.com/design_patterns/prototypehttp://sourcemaking.com/design_patterns/singletonhttp://sourcemaking.com/design_patterns/singletonhttp://sourcemaking.com/design_patterns/prototypehttp://sourcemaking.com/design_patterns/object_poolhttp://sourcemaking.com/design_patterns/factory_methodhttp://sourcemaking.com/design_patterns/builderhttp://sourcemaking.com/design_patterns/abstract_factory8/14/2019 Part2 Adapter Pattern
5/16
8/14/2019 Part2 Adapter Pattern
6/16
Adapter pattern -
IntentConvert the interface of a class into anotherinterface clients expect.
Adapter lets classes work together that couldnt
otherwise because of incompatible interfaces.
Wrap an existing class with a new interface.
Match an old component to a new system
8/14/2019 Part2 Adapter Pattern
7/16
Adapter pattern -
ProblemAn off the shelf component offerscompelling functionality that you would
like to reuse, but its view of the worldis not compatible with the philosophy andarchitecture of the system currentlybeing developed.
8/14/2019 Part2 Adapter Pattern
8/16
Adapter pattern -
MotivationWhen we want to reuse classes in an applicationthat expects classes with a different interface, we donot want (and often cannot) to change the reusableclasses to suit our application.
Adapter is about creating an intermediaryabstraction that translates, or maps, the oldcomponent to the new system. Clients call methodson the Adapter object which redirects them into callsto the legacy component. This strategy can beimplemented either with inheritance orwith aggregation.
Adapter functions as a wrapper or modifier of an
existing class. It provides a different or translated
8/14/2019 Part2 Adapter Pattern
9/16
Adapter pattern
8/14/2019 Part2 Adapter Pattern
10/16
Adapter pattern
8/14/2019 Part2 Adapter Pattern
11/16
How the client uses
the Adapter patternThe clients make a request to the adapter bycalling a method on it using the target
interface .
The adapter translates that request into oneor more calls on the adaptee using theadaptee Interface.
The client receives the results of the call andnever knows there is an adapter doing the
Translation .
8/14/2019 Part2 Adapter Pattern
12/16
Adapter pattern -
Structure
8/14/2019 Part2 Adapter Pattern
13/16
Adapter pattern -
Structure
8/14/2019 Part2 Adapter Pattern
14/16
Software Design (OODPatterns(
Participants of theAdapter Pattern
Target: Defines the application-specificinterface that clients use.
Client: Collaborates with objects
conforming to the target interface.
Adaptee: Defines an existing interfacethat needs adapting.
Adapter: Adapts the interface of theadaptee to the target interface.
8/14/2019 Part2 Adapter Pattern
15/16
Software Design (OODPatterns(
Example - AdapterPattern
Ad ti
8/14/2019 Part2 Adapter Pattern
16/16
Software Design (OODPatterns(
Adapting anEnumeration to an
Iterator