装饰者设计模式的使用

来源:互联网 发布:淘宝网汉服 编辑:程序博客网 时间:2024/05/17 06:44
装饰者模式: --- 缺点:接口中的方法过多.重写接口中的所有的方法.* 被增强的类 需要 与 要增强 实现相同的接口.* 在增强的类中 需要能够获得被增强类的引用.interface IPerson{public void run();}class Person implements IPerson{public void run(){System.out.println("能跑100米...");}}class PersonWrapper implements IPerson{private IPerson iperson;public PersonWrapper(IPerson iperson) {this.iperson = iperson;}@Overridepublic void run() {//iperson.run();System.out.println("我是增强的类 能跑 500米...");}}

0 0
原创粉丝点击