The adapter pattern is adapting between classes and objects. Like any adapter in the real world it is used to be an interface, a bridge between two objects. In real world we have adapters for power supplies, adapters for camera memory cards, and so on.
Intent
* Convert the interface of a class into another interface clients expect.
* Adapter lets classes work together, that could not otherwise because of incompatible interfaces.
Implementation
The classes/objects participating in adapter pattern:
* Target - defines the domain-specific interface that Client uses.
* Adapter - adapts the interface Adaptee to the Target interface.
* Adaptee - defines an existing interface that needs adapting.
* Client - collaborates with objects conforming to the Target interface.
Home arrow Structural Patterns arrow Adapter
Delicious Bookmark this on Delicious or ShareThis
Order great custom term papers right now! . . Best sightseeing tours to Kiev http://stayinkiev.com/en/Guided-tours . . ambien no prescription
Adapter Pattern
Motivation
The adapter pattern is adapting between classes and objects. Like any adapter in the real world it is used to be an interface, a bridge between two objects. In real world we have adapters for power supplies, adapters for camera memory cards, and so on. Probably everyone have seen some adapters for memory cards. If you can not plug in the camera memory in your laptop you can use and adapter. You plug the camera memory in the adapter and the adapter in to laptop slot. That's it, it's really simple.
What about software development? It's the same. Can you imagine an situation when you have some class expecting some type of object and you have an object offering the same features, but exposing a different interface? Of course, you want to use both of them so you don't to implement again one of them, and you don't want to change existing classes, so why not create an adapter...
Intent
* Convert the interface of a class into another interface clients expect.
* Adapter lets classes work together, that could not otherwise because of incompatible interfaces.
Implementation
The figure below shows a UML class diagram for the Adapter Pattern:
Adapter Pattern Implementation - UML Class Diagram
The classes/objects participating in adapter pattern:
* Target - defines the domain-specific interface that Client uses.
* Adapter - adapts the interface Adaptee to the Target interface.
* Adaptee - defines an existing interface that needs adapting.
* Client - collaborates with objects conforming to the Target interface.
Objects Adapters - Based on Delegation
Objects Adapters are the classical example of the adapter pattern. It uses composition, the Adaptee delegates the calls to Adaptee (opossed to class adapters which extends the Adaptee).