Adapter (owner of design)

In software Genius, Adaptateur is a Patron of design (design pattern) of the type structure (structural) .

Goal

It makes it possible to convert the interface of a class into another interface until the customer waits. Adaptateur makes function together classes which could not without him, because of an incompatibility of interfaces.

Another name

Wrapper

Motivation/Example

You want to integrate a class that you do not want/cannot to modify.

Applicability

  • an API Third is appropriate for your functional need, but the signature of its methods is not appropriate to you.
  • You want to standardize the use of old classes without to take again all the code of it.

Structure

Participants

  • IAdaptateur : The interface trade defines used by the Client .
  • Customer : Work with objects implementing the interface IAdaptateur .
  • Adapted : Defines an existing interface having to be adapted.
  • Adapter : Fact of corresponding the interface of Adapted to the interface IAdaptateur .

Collaboration

Consequences

An object Adaptateur is used as connection between the handled objects and a program using them, to simplify the communication between two classes. It is used to modify the interface of an object towards another interface.

Implementation

Example of code

Known uses

One can also use an adapter when one does not want to implement all the methods of a certain interface. For example, if one must implement the MouseListener interface in Java, but which one does not wish to implement of behavior for all the methods, one can derive the MouseAdapter class. This one indeed provides a behavior by defect (vacuum) for all the methods of MouseListener.

Example with MouseAdapter: public class MouseBeeper extends MouseAdapter { public void mouseClicked (MouseEvent E) { Toolkit.getDefaultToolkit () .beep (); } }

Example with MouseListener: public class MouseBeeper implements MouseListener { public void mouseClicked (MouseEvent E) { Toolkit.getDefaultToolkit () .beep (); }

public void mousePressed (MouseEvent E) {} public void mouseReleased (MouseEvent E) {} public void mouseEntered (MouseEvent E) {} public void mouseExited (MouseEvent E) {} }

See too

Related articles

External bonds and documents

  • Adapter on DoFactory

Random links:Luis Von Drake | Roast data-processing | Jake Gyllenhaal | Snafu privado | Island the Broad one | Darwin Project | Gerald sergeant | TDRSS