public interface Writer {
public void write(String s);
}
public class SystemOutPrinter {
public void printToSystemOut(String s) {
System.out.println(s);
}
}
public aspect PrinterAdapter {
declare parents: SystemOutPrinter implements Writer;
public void SystemOutPrinter.write(String s) {
printToSystemOut(s);
}
}
public class Main {
* In this implementation, the Adaptee becomes its own
* Adapter, so only one variable is needed.
public static void main(String[] args) {
System.out.println("Creating Adaptee (which is its own Adapter)...");
adaptee = new SystemOutPrinter();
System.out.print ("Adapter and Adaptee are the same object: ");
System.out.println(adaptee == adaptee);
System.out.println("Issuing the request() to the Adapter...");
adaptee.write("Test successful.");
}
}
Take a look at our introductions example:
http://www.jboss.org/jbossaop/docs/2.0.0.GA/docs/aspect-framework/examples/introductions/introductions.html