package Java设计模式.代理设计模式;
/**
* 这里我们可以发现One类中方法已经被Two类代为实现了,而且还附加了额外的功能哈哈。
*/
interface Flower
{
void show();
}
class One implements Flower
{
@Override
public void show() {
System.out.println("开花结果");
}
}
class Two implements Flower
{
One one;
public Two()
{
super();
this.one=new One();
}
@Override
public void show() {
before();
one.show();
after();
}
void before()
{
System.out.println("before");
}
void after()
{
System.out.println("after");
}
}
public class Test {
public static void main(String[] args) {
Two two=new Two();
two.show();
}
}
Java设计模式之代理设计模式
猜你喜欢
转载自blog.csdn.net/weixin_43562705/article/details/89438323
今日推荐
周排行