标签:com override ati this 美颜 decorator 设计模式 rgb nts
装饰者模式:
在不改变原有对象的基础上,将功能附加到对象上
/** * 装饰者模式 */ public class decoratorTest { public static void main(String[] args) { Component component = new ConcreteDecorator2(new ConcreteDecorator1(new concreteComponent())); component.operation(); } } interface Component{ void operation(); } class concreteComponent implements Component{ @Override public void operation() { System.out.println("拍照.."); } } abstract class Decorator implements Component{ Component component; public Decorator(Component component) { this.component = component; } } class ConcreteDecorator1 extends Decorator{ public ConcreteDecorator1(Component component) { super(component); } @Override public void operation() { System.out.println("添加美颜.."); component.operation(); } } class ConcreteDecorator2 extends Decorator{ public ConcreteDecorator2(Component component) { super(component); } @Override public void operation() { System.out.println("添加滤镜.."); component.operation(); } }
标签:com override ati this 美颜 decorator 设计模式 rgb nts
原文地址:https://www.cnblogs.com/chenfx/p/14788129.html