public class WrapperTest {
public static void main(String[] args) {
/**
拍照
*/
// Componnet conCreateComponnet = new ConCreateComponnet();
// conCreateComponnet.operation();
/**
添加美颜
拍照
*/
// Componnet decorator = new ConDecorator1(new ConCreateComponnet());
// decorator.operation();
/**
添加滤镜
添加美颜
拍照
*/
Componnet decorator = new ConDecorator2(new ConDecorator1(new ConCreateComponnet()));
decorator.operation();
}
}
interface Componnet {
void operation();
}
class ConCreateComponnet implements Componnet {
@Override
public void operation() {
System.out.println("拍照");
}
}
abstract class Decorator implements Componnet {
protected Componnet componnet;
public Decorator(Componnet componnet) {
this.componnet = componnet;
}
}
class ConDecorator1 extends Decorator {
public ConDecorator1(Componnet componnet) {
super(componnet);
}
@Override
public void operation() {
System.out.println("添加美颜");
componnet.operation();
}
}
class ConDecorator2 extends ConDecorator1 {
public ConDecorator2(Componnet componnet) {
super(componnet);
}
@Override
public void operation() {
System.out.println("添加滤镜");
componnet.operation();
}
}