Adapter - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Adapter

Description:

Change the interface of a class into another interface which is expected by the client. ... http://www.javaworld.com/javaworld/jw-05-1999/jw-05-networked.html ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 18
Provided by: GuyD1
Category:
Tags: adapter | class

less

Transcript and Presenter's Notes

Title: Adapter


1
Adapter
  • SENG 609.04 Design Patterns
  • Winter, 2003
  • Presented by Ming Zhou, Guy Davis

2
Agenda
  • Intent Motivation
  • Structure
  • Applicability
  • Consequences
  • Known Uses
  • Related Patterns
  • References

3
What is Adapter?
  • Change the interface of a class into another
    interface which is expected by the client.
  • A.K.A. Wrapper

4
Motivation
5
Structure (Class)
6
Structure (Object)
7
Applicability
  • Use an existing class whose interface does not
    match the requirement
  • Create a reusable class though the interfaces are
    not necessary compatible with callers

8
Class Adapter Pattern
  • Pros
  • Only 1 new object, no additional indirection
  • Less code required than the object Adapter
  • Can override Adaptee's behaviour as required
  • Cons
  • Requires sub-classing (tough for single
    inheritance)
  • Less flexible than object Adapter

9
Object Adapter Pattern
  • Pros
  • More flexible than class Adapter
  • Doesn't require sub-classing to work
  • Adapter works with Adaptee and all of its
    subclasses
  • Cons
  • Harder to override Adaptee behavior
  • Requires more code to implement properly

10
Pluggable Adapters
  • implemented with abstract operations

11
Pluggable Adapters
  • implemented with delegate objects

12
Two-way Adapters
class PegAdapter public SquarePeg, RoundPeg
public void virtual roundPegOperation()
add some corners
squarePegOperation() void virtual
squarePegOperation() add some
corners roundPegOperation()
  • class SquarePeg
  • public
  • void virtual squarePegOperation() blah

class RoundPeg public void virtual
roundPegOperation() blah
13
Adapting Local Classes to RMI
  • Comparison
  • Increases reusability of local class
  • Improves performance of local class
  • Doesn't use Java single parent by subclassing
    (uses composition)

14
Related Patterns
  • Adapter can be similar to the remote form of
    Proxy. However, Proxy doesn't change interfaces.
  • Decorator enhances another object without
    changing its interface.
  • Bridge similar structure to Adapter, but
    different intent. Separates interface from
    implementation.

15
Conclusions
  • Allows collaboration between classes with
    incompatible interfaces
  • Implemented in either class-based (inheritance)
    or object-based (composition delegation) manner
  • Useful pattern which promotes reuse and allows
    integration of diverse software components

16
References
  • Becker, Dan. Design networked applications in RMI
    using the Adapter design pattern. JavaWorld
    Magazine, May 1999. http//www.javaworld.com/javaw
    orld/jw-05-1999/jw-05-networked.html
  • Buschmann et al. A System of Patterns
    Pattern-Oriented Software Architecture. John
    Wiley and Sons. Chichester. 1996
  • Gamma et al. Design Patterns Elements of
    Reusable Object-Oriented Software.
    Addison-Wesley. Boston. 1995
  • Nguyen, D.X. Tutorial 10 Stacks and Queues The
    Adapter Pattern. Rice University. 1999.
    http//www.owlnet.rice.edu/comp212/99-fall/tutori
    als/10/tutorial10.html
  • Whitney, Roger. CS 635 Advanced Object-Oriented
    Design Programming. San Diego State University.
    2001. http//www.eli.sdsu.edu/courses/spring01/cs6
    35/notes/proxy/proxy.htmlHeading10
  • Shalloway, Alan., and Trott, James R., Design
    Patterns Explained A New Perspective on
    Object-Oriented Design, Addison-Wesley, 2002.
  • Rising, Linda., The Patterns Handbook
    Techniques, Strategies, and Applications,
    Cambridge university Press, 1998.

17
Questions?
Write a Comment
User Comments (0)
About PowerShow.com