public interface IMoudle {
void build();
}
public class PhoneFrame implements IMoudle {
@Override
public void build() {
System.out.println("构建手机基础框架");
}
}
public class DecoratorMoudle implements IMoudle {
protected IMoudle imoudle;
public DecoratorMoudle(IMoudle moudle){
imoudle=moudle;
}
@Override
public void build() {
System.out.println("doingNothind");
}
}
public class Battery extends DecoratorMoudle {
private int mAh;
public Battery(IMoudle targetMoudle, Integer mAh) {
super(targetMoudle);
this.mAh = mAh;
}
@Override
public void build() {
imoudle.build();
System.out.println("接入电池完成,容量:" + mAh+"mAH");
}
}
public class CPU extends DecoratorMoudle {
private String cpuName;
public CPU(IMoudle targetMoudle, String cpuName) {
super(targetMoudle);
this.cpuName = cpuName;
}
@Override
public void build() {
imoudle.build();
System.out.println("接入CPU完成,型号:" + cpuName);
}
}
public class App {
public static void main(String[] args) {
IMoudle phone = new Battery(new CPU(new PhoneFrame(), "A8"), 5000);
phone.build();
System.out.println("phone构建完毕");
}
}