Friday, 23 March 2007

Adapter Pattern

As name implies Adapter pattern is used to allow incompatible classes/objects work together. Without modifying the client’s object who wishes to use another object whose interfaces or data types doesn’t match, adapter object/class can be implemented to solve the problem.

Adapter pattern can be applied for classes and for objects.
In Class Adapter;



the adapter class multiple inherits adoptee class and the clients target (interface) class. Because JAVA does not permit multiple inheritances, either one has to be adapted as Java interface type.

In Object Adapter;
In Object Adapter; Adapter contains the instance of the Adaptee and inherits the Client’s Target interface. When Client calls Target object the request is translated into request of the Adaptee object.

Image Source:
http://staff.aist.go.jp/y-ichisugi/ja/mj/design-pattern/fig-GoF/PNG/adapter1.png
http://staff.aist.go.jp/y-ichisugi/ja/mj/design-pattern/fig-GoF/PNG/adapter2.png

No comments: