|
Thursday, 20 January 2005 21:33 |
Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

Source Code/**
* Defines an existing interface that needs adapting
*
* @role __Adaptee
*/
public class Adaptee {
/* Some adaptee-specific behavior */
public void specificRequest() {
// some adaptee specific stuff is going here
}
}
/**
* This class adapts the interface of Adaptee to the Target interface
*/
public class Adapter extends Target {
/** reference to the object being adapted */
private Adaptee adaptee;
/**
* @param adaptMe
* class to adapt whis this adapter
*/
public Adapter(Adaptee adaptMe) {
this.adaptee = adaptMe;
}
/**
* Implementation of target method that uses adaptee to perform task
*/
public void request() {
adaptee.specificRequest();
}
}
/**
* This class defines domain-specific interface used by client
*
* @role __Target
*/
public abstract class Target {
/** This method is called by client when he needs some domain-specific stuff */
public abstract void request();
}
|
|
Last Updated ( Saturday, 18 June 2005 00:11 )
|