public class JavaProxyDemo {
public static void main(String[] args) {
EatProxy eatProxy = new EatProxy(new EatReal());
eatProxy.eat();
}
}
interface IEat{
public void eat();
}
class EatReal implements IEat{
public void eat(){
System.out.println("[吃饭过程核心]");
}
}
class EatProxy implements IEat{
private IEat eat;
public EatPorxy(IEat eat){
this.eat = eat;
}
public void foot(){
System.out.println("[吃饭之前准备食材]");
}
public void clear(){
System.out.println("[吃完饭清理]");
}
public void eat(){
this.foot();
this.eat.eat();
this.clear();
}
}
如果你喜欢,可以关注我的公众号