Structural Patterns
ADAPTOR PATTERN:
The Gang Of Four (GoF) defined the Adaptor pattern as follows in their most famous book "Design Patterns" Gamma et al., Addison-Wesley, ISBN:0-201-63361-2" - "Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces."
During object-oriented developments, some times we have to use an unrelated class along with our existing class hierarchy. The simplest solution is to make a wrapper or adaptor around the foreign class, which is acceptable by the existing class hierarchy. This is what known as the ADAPTOR PATTERN or WRAPPER PATTERN.
Let us see the following class hierarchy. 
How we can fit a foreign class or interface say ADAPTEE to this class hierarchy. It is possible by introducing an ADAPTOR class as shown below.
In the above case the ADAPTOR class inherits from both BASE CLASS & ADAPTEE class. This type of mechanism based on the multiple inheritances is known as class adaptors. Remember that this may be introducing the violation of Open Closed Principle (OCP) or Lisknov's Substitution Principle (LSP). But if we are using class adaptors, better to use a private inheritance with respect to the ADAPTEE class.
Instead of inheriting from the ADAPTEE class, the ADAPTOR class can contain an instance of ADAPTEE class and use that instance. This mechanism employs the object adaptors. The UML representation of Object adaptor is shown below.
In class adaptor, it is possible to override some of the behaviors of the ADAPTEE class in ADAPTOR class. But class adaptor will not work when we want to adapt ADAPTEE class and all its derived classes.
But an object adaptor can work with the ADAPTEE class and all its subclasses.
Non-software Example
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Nathaniel TabinPosted Jul 17, 2019, 12:36 AM
Thanks for using a very simple example and easy to understand
Vijendra KushwahaPosted Dec 18, 2015, 3:11 PM
Great explanation. Thanks
vijay chauhanPosted Apr 26, 2014, 2:15 PM
can u tell me what are the application area of ur design pattern , means where we can use this ?
sathaliyawala sathalyaPosted Nov 30, 2011, 1:18 AM
please can you explain factory and abstract factory with example
Manikavelu VelayuthamPosted Nov 29, 2011, 4:03 AM
Good One.