标签:定义 ora ted method oid 模式 system 设计模式 override
被装饰对象 调用 装饰对象的同一个接口方法,实现被装饰对象的方法
//定义共用接口
public interface ILog {
public void log(String message);
}
public class UserLog implements ILog{
@Override
public void log(String message) {
// TODO Auto-generated method stub
System.out.println("装饰对象的方法"+message);
}
}//
public class Decorator implements ILog{
private ILog usrLog;public Decorator(ILog usrLog) {
super();
this.usrLog = usrLog;
}@Override
public void log(String message) {
// TODO Auto-generated method stub
System.out.println("被装饰前");
this.usrLog.log(message);
System.out.println("被装饰后");
}
}
public class Demo {
public static void main(String[] args) {
Decorator decorator = new Decorator(new UserLog());
decorator.log("hello Decorator model");
}
}
标签:定义 ora ted method oid 模式 system 设计模式 override
原文地址:https://www.cnblogs.com/macro-renzhansheng/p/12568524.html