装饰者模式的典型应用输入输出流。
public interface Component {
public String operation();
}
public class ConcreteComponent implements Component{
public String operation() {
return "concreteComponent:" ;
}
}
public class Plan {
public void doOperation() {
}
}
public class PlanDecorator extends Plan{
Component component ;
public PlanDecorator(Component component ) {
this .component = component;
}
public void doOperation() {
System. out .println( "Decorator : " + component .operation() );
}
}
public class DecoratorClient {
public static void main(String[] args) {
Component component = new ConcreteComponent();
Plan planDecorator = new PlanDecorator(component);
planDecorator.doOperation();
}
}