Recommended sites

Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati
Add to BlinkBits
Adapter Print E-mail
User Rating: / 0
PoorBest 
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();
}
Comments
Add New Search RSS
Write comment
Name:
Email:
 
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
:):grin;)8):p:roll:eek:upset:zzz:sigh:?:cry
:(:x
Please input the anti-spam code that you can read in the image.

3.20 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Saturday, 18 June 2005 00:11 )
 


Another articles:


Content View Hits : 2512693

Enter Amount: