Your SlideShare is downloading. ×
0
Adapter
Adapter
Adapter
Adapter
Adapter
Adapter
Adapter
Adapter
Adapter
Adapter
Adapter
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Adapter

546

Published on

Object-oriented analysis and design(OOAD) and Design Pattern Slides UML Slides. for more slides refer www.scmGalaxy.com

Object-oriented analysis and design(OOAD) and Design Pattern Slides UML Slides. for more slides refer www.scmGalaxy.com

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
546
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Adapter Object Diagram for Adapter using Socket Adapter Example The Adapter pattern allows otherwise incompatible classes to work together by converting the interface of one class into an interface expected by the clients. Socket wrenches provide an example of the Adapter . A socket attaches to a ratchet, provided that the size of the drive is the same. Typical drive sizes in the United States are 1/2" and 1/4". Obviously a 1/2" drive ratchet will not fit into a 1/4" drive socket unless an adapter is used. A 1/2" to 1/4" adapter has a 1/2" female connection to fit on the 1/2" drive ratchet, and a 1/4" male connection to fit in the 1/4" drive socket.
  • 2. <ul><li>Intent </li></ul><ul><li>  Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. </li></ul><ul><li>  Alternative Name: </li></ul><ul><li>Wrapper </li></ul><ul><li>Problem </li></ul><ul><li>An &quot;off the shelf&quot; component offers compelling functionality that you would like reuse, but its &quot;view of the world&quot; is not compatible with the philosophy and architecture of the system currently being developed </li></ul>
  • 3. <ul><li>Illustration: Problem </li></ul><ul><li>The classes in the tool kit (Text View in figure ) may not be exactly what the client needs, so it becomes difficult for the client to reuse such a class directly. </li></ul><ul><li>Due to this difficulty one may be tempted to duplicate the code which will cause redundancy . </li></ul>
  • 4. <ul><li>Solution: </li></ul><ul><li>One way to solve this problem is to make the client class ( TextShape ) to adapt the Tool Kit Class ( TextView ) and modify the interface to suit there application. This can be done in two ways </li></ul><ul><li>1 >       By additionally inheriting the TextView Class or </li></ul><ul><li>2>       Keeping a reference of the tool kit class inside the Test Shape Class. </li></ul><ul><li>The second method is preferred over the first method as the client hierarchy is kept low in depth, also we are aware of the problems of multiple inheritance. </li></ul>
  • 5. Applicability <ul><li>Use the Adapter pattern when </li></ul><ul><li>  </li></ul><ul><li>You want to use an existing class, and its interface does not match the one you need. </li></ul><ul><li>  </li></ul><ul><li>You want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don’t necessarily have compatible interfaces. </li></ul><ul><li>  </li></ul><ul><li>(Object adapter only) you need to use several existing subclasses, but it’s impractical to adapt their interface by subclassing every one. An object adapter can adapt the interface of its parent class. </li></ul>
  • 6. Structure
  • 7. Collaborations <ul><li>Clients call operations on an Adapter instance. In turn, the adapter calls Adaptee operations that carry out the request. </li></ul>Class and object adapters have different trade-offs . A class adapter: 1. Adapts Adapter to target by committing to a concrete Adapter class . As a consequence, a class adapter won’t work when we want to adapt a class and all its subclasses. 2. Lets-adapter override some of Adaptee’s behavior, since Adapter is a subclass of Adaptee.   3. Introduces only one object, and no additional pointer indirection is needed to get to the Adaptee Consequences
  • 8. Consequences conti… <ul><li>  </li></ul><ul><li>Issues to be considered while using adapter pattern: </li></ul><ul><li>1.  How much adapting does Adapter do? </li></ul><ul><li>Pluggable adapters. </li></ul><ul><li>Using two-way adapters to provide transparency. </li></ul>B Object adapter: 1. Lets a single adapter work with many Adaptees-that is, the Adaptee itself and all of its subclasses (if any). The Adapter can also add functionality to all Adaptees at once. 2. Makes it harder to overide Adaptee behavior. It will require subclassing Adaptee and making Adapter refer to the subclass rather than the Adapter itself.
  • 9. Related pattern <ul><li>Bridge has a structure similar to an object adapter, but Bridge has a different intent: It is meant to separate an interface from its implementation so that they can be varied easily and independently. An adapter is meant to change the interface of an existing object. </li></ul><ul><li>Decorator enhances another object without changing its interface. A decorator is thus more transparent to the application than an adapter is. As a consequence, Decorator supports recursive composition, which isn’t possible with pure adapter. </li></ul>
  • 10. <ul><li>Model: Adapter Class Pattern </li></ul>1
  • 11. <ul><li>Model: Adapter object Pattern </li></ul>1

×