/**
* 代理模式是用一个代理类对象代替原对象执行原来对象的方法
* 在执行过程中可以根据需要执行相关的其他代码
* @author
* @version 0.1
*/
public interface Sourceable {
void method();
}
/**
* @author
* @version 0.1
*/
public class User implements Sourceable {
@Override
public void method() {
System.out.println("The method() in User.");
}
}
/**
* @author
* @version 0.1
*/
public class Proxy implements Sourceable {
private User user;
public Proxy(){
super();
this.user = new User();
}
private void beforeMethod(){
System.out.println("This method is excuted before method.");
}
private void afterMethod(){
System.out.println("This method is excuted after method.");
}
@Override
public void method() {
this.beforeMethod();
user.method();
this.afterMethod();
}
}
/**
* @author
* @version 0.1
*/
public class Test {
public static void main(String[] args) {
Sourceable user = new Proxy();
user.method();
}
}