Your SlideShare is downloading. ×
0
Adapter design pattern Melbourne Design Patterns User Group Russell Searle 6 May 2009
Structural patterns <ul><li>Compose and assemble classes and objects </li></ul><ul><li>Structural  class  patterns inherit...
Adapter pattern <ul><li>Converts a class interface into a different interface expected by clients </li></ul><ul><li>Enable...
Why use adapter pattern? <ul><li>You can’t reuse a candidate class because its interface doesn’t match client or domain re...
Class adapter <ul><li>Uses single / multiple inheritance to transform interfaces </li></ul><ul><li>Implements a specific A...
Object adapter <ul><li>Composes objects, uses delegation </li></ul><ul><li>Composition may be changed at run-time </li></u...
Design considerations <ul><li>Complexity of adapter depends on scope of function it adapts: integration work is often very...
Example
Related patterns <ul><li>Bridge  has similar structure, but is intended to make an interface and its implementation indepe...
Sources <ul><li>Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides.  Design patterns: elements of reusable object...
Upcoming SlideShare
Loading in...5
×

Adapter Design Pattern

702

Published on

Presented to Melbourne Design Patterns Group on 6 May 2009

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

  • Be the first to like this

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

No notes for slide

Transcript of "Adapter Design Pattern"

  1. 1. Adapter design pattern Melbourne Design Patterns User Group Russell Searle 6 May 2009
  2. 2. Structural patterns <ul><li>Compose and assemble classes and objects </li></ul><ul><li>Structural class patterns inherit from adaptees </li></ul><ul><ul><li>Adapter </li></ul></ul><ul><li>Structural object patterns compose objects </li></ul><ul><ul><li>Adapter </li></ul></ul><ul><ul><li>Bridge </li></ul></ul><ul><ul><li>Composite </li></ul></ul><ul><ul><li>Decorator </li></ul></ul><ul><ul><li>Façade </li></ul></ul><ul><ul><li>Flyweight </li></ul></ul><ul><ul><li>Proxy </li></ul></ul>
  3. 3. Adapter pattern <ul><li>Converts a class interface into a different interface expected by clients </li></ul><ul><li>Enables interoperation of unlike classes </li></ul><ul><li>aka: Wrapper </li></ul><ul><li>Useful in integration work, as a technique and architectural principle </li></ul>
  4. 4. Why use adapter pattern? <ul><li>You can’t reuse a candidate class because its interface doesn’t match client or domain requirements </li></ul><ul><li>You want to create a reusable class that combines existing, unlike classes </li></ul><ul><li>You need to use existing subclasses but you can’t subclass all of them </li></ul>
  5. 5. Class adapter <ul><li>Uses single / multiple inheritance to transform interfaces </li></ul><ul><li>Implements a specific Adaptee class, so you can’t also adapt the Adaptee’s subclasses </li></ul><ul><li>Can override Adaptee behaviour </li></ul><ul><li>Produces only one new object </li></ul>
  6. 6. Object adapter <ul><li>Composes objects, uses delegation </li></ul><ul><li>Composition may be changed at run-time </li></ul><ul><li>Can implement or extend more than one Adaptee class (if allowed) </li></ul><ul><li>May complicate overriding Adaptee behaviour </li></ul>
  7. 7. Design considerations <ul><li>Complexity of adapter depends on scope of function it adapts: integration work is often very demanding </li></ul><ul><li>May design adapters for maximum reuse by generalising its elements: pluggable adapters </li></ul><ul><li>Two-way adapters to implement interfaces from all sides of the problem domain, in order to integrate them </li></ul>
  8. 8. Example
  9. 9. Related patterns <ul><li>Bridge has similar structure, but is intended to make an interface and its implementation independent </li></ul><ul><li>Decorator elaborates another object without changing its interface; can also support recursion </li></ul><ul><li>Proxy produces a stand-in for another object without changing its interface </li></ul>
  10. 10. Sources <ul><li>Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides. Design patterns: elements of reusable object-oriented software. Addison-Wesley, Reading, MA, 1995. </li></ul><ul><li>David Geary. Adopt Adapter. JavaWorld.com, http://www.javaworld.com/javaworld/jw-09-2003/jw-0926-designpatterns.html , 26 Sept 2003. </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×