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();
}

Tags See All Tags Add New Tag...

Please Enter New Tags Separated By Comma's
  Or Close

designpattern  java 
Powered By Joomla Tags

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 on Saturday, 18 June 2005 00:11
 


Another articles:

Powered By relatedArticle

Content View Hits : 3463946

Enter Amount: