Monday, June 25, 2012

adapter pattern

AN OBJECT IS A client if it needs to call your code.

For example, a rocket-simulation program might be designed to use rocket information that you supply, but such a simulation will have its own definition of how a rocket should behave. In such circumstances, you may find that an existing class performs the services that a client needs but has different method names. In this situation, you can apply the ADAPTER pattern.

The intent of ADAPTER is to provide the interface that a client expects while using the services of a class with a different interface.

The ADAPTER pattern lets you use an existing class to meet a client class’s needs.

When a client specifies its requirements in an interface, you can usually create a new class that implements the interface and subclasses an existing class.
This approach creates a class adapter that translates a client’s calls into calls to the existing class’s methods.




In computer programming, the adapter pattern (often referred to as the wrapper pattern or simply a wrapper) is a design pattern that translates one interface for a class into a compatible interface.

An adapter allows classes to work together that normally could not because of incompatible interfaces, by providing its interface to clients while using the original interface.

The adapter translates calls to its interface into calls to the original interface, and the amount of code necessary to do this is typically small. The adapter is also responsible for transforming data into appropriate forms

http://en.wikipedia.org/wiki/Adapter_pattern

No comments:

Post a Comment