Sometimes we need to change the interface of a class in order to be usable for a client. This could happen due to various reasons such as the existing interface may be too detailed, or it may lack details or the terminology used by the interface may be different from what the client is looking for.
The Adapter pattern suggests defining a wrapper class around the object with the incompatible
interface. This wrapper object is referred as an adapter and the object it wraps is referred to as an adaptee. The adapter provides the required interface expected by the client. The implementation of the adapter interface converts client requests into calls to the adaptee class interface.
There are two types of adapters, Class Adapter and *Object Adapter*. Class Adapter is based on inheritance and inherits the adaptee class. Object Adapter works based on composition and has a reference to the adaptee object. Both should implement the interface which the client expects.
public class Client { Adapter adapter; ... adapter.doWork(some_interface); ... } //client actually wants to call action(some_other_interface) public class Adaptee{ ... Public SomeWork action(some_other_interface){ ... } } //composition adapter public class Adapter{ Adaptee adaptee; public SomeWork doWork(some_interface){ ... adaptee.action(some_other_interface); ... } } //inheritance adapter public class Adapter extends Adaptee{ ... public SomeWork doWork(some_interface){ ... adaptee.action(some_other_interface); ... } }





