1.模式定义:在不改变原有对象的基础上,将功能附加到对象上
interface Phone{ //定义一个手机接口void operation(); //定义拍照操作功能接口}class HuaWeiP30 implements Phone{ //华为P30实现了手机拍照@Overridepublic void operation() {System.out.println("拍照。。。");}}abstract class Decorator implements Phone{ //定义装饰Phone component;public Decorator(Phone component) {this.component = component;}}class MeiYan extends Decorator{ //添加美颜功能public MeiYan(Phone component) {super(component);}@Overridepublic void operation() {component.operation();System.out.println("美颜...");}}class LvJin extends Decorator{ //添加滤镜功能public LvJin(Phone component) {super(component);}@Overridepublic void operation() {component.operation();System.out.println("滤镜...");}}public class DecoratorTest {public static void main(String[] args) {Phone component = new LvJin(new MeiYan(new HuaWeiP30()));component.operation();}}

应用场景:
扩展一个类的功能或给一个类添加附加职责
优点:
1.不改变原有对象的情况下给一个对象扩展功能
2.使用不同的组合可以实现不同的效果
3.符合开闭原则
经典案例
1ServletApi:
2javax.servlet.http.HttpServletRequestWrapper
3javax.servlet.http.HttpServletResponseWrapper
