Wednesday, April 18, 2007

Behavioral Pattern-Adapter

There are two kind of the adapters in adapter pattern.Those are Object adapter and Class adapter.This two kind of adapters give two different meaning for adaptee and adapter.

The follwing diagram helped me to understand about the difference between two of them.

Class Adapter


Client
  • The Client class call to Target class.
Adapter

  • The Adapter extend both classes.It can take target method calls and turn around method on adaptee.But Adaptee class does not have same method.
  • There are some more advanage of adapter class.The adapter class is commited to one specific adapter class.
Adaptees

  • The class adapter doesn't need to implement entire adaptee class, because adapter class inherit adaptee class and it also sub class of the adaptee.It also overide behavior of adapter.
Comparing to object adapter class adapter require less code than object adapter.

Limitation

  • Less flexible than object adapter
  • its very tough for single inheritance.
Object adapter









  • One advantage of the of object adapter is its more flexible than class adapter.
  • It work with adaptee and all of subclasses.
Limitation
  • It reuqire more code to implement than adapter class.

Rerefences

  1. Davis Guy/Zhou Ming,Java native interface(JNI)/SENG 609.04 Desing Patterns-2003/http://www.guydavis.ca/projects/presentations/adapter/adapter.ppt#271,16,References
  2. Whitney Roger/CS 635 Advanced Object Oriented Desing and Programing/San Diogo State University - 2001 - http://www.eli.sdsu.edu/courses/spring01/cs635/notes/proxy/proxy.html#Heading10.

Behavioral Patterns-Adapter

Adapter Pattern

As a student of PAFSD,this week i try to understand about the adapter pattern which will helpful for my coursework first question. After read a "Head first design pattern book and related websites i understood valuable information about adapter pattern help for software development.

What i learnt about this Pattern

The adapter pattern allows classes work together, which have incompatible interfaces in system. It acts as a middle man by receiving request from the client and converting them into request that make what exactly client expect. In software re-engineering or reuse process, some times we meet incompatible interfaces to join each other to run system.

The main reasons for this problem are took kit or class libraries are incompatible with interface with new system. Then software developer use adapter to create reusable class that corporate with incompatible interfaces to get exception interfaces. The following definition is the most understandable definition for me about the adapter pattern.

The following definition is the most understandable definition for me about the adapter pattern.

The Adapter Pattern

"converts the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces".
Head First Design Patterns- ISBN 0-596-00712-4

!!! When i was considering about the above things, i had question about adapter pattern.

What happen the systems have old system interface and new system interface? Its bit confusing to create a adapter pattern.

Further reading about the Head first book i realised we can create two way adapter to solve a this problem.The two way adapter supports both interfaces to match old vender class and new vender class.



Following link will give you good idea about the Adapter pattern.
http://www.research.umbc.edu/~tarr/dp/lectures/Adapter-2pp.pdf.