public interface SuperStar {
public void perform();
}
public class Singer implements SuperStar {
@Override
public void perform() {
System.out.println("singing a song!");
}
}
public class StarProxy implements SuperStar {
private SuperStar superStar;
private boolean busyState;
public StarProxy(boolean busyState){
superStar = new Singer();
this.busyState = busyState;
}
@Override
public void perform() { //通过true false 判断是否演出
if (busyState){
superStar.perform();
}else{
System.out.println("行程已满,无法演出");
}
}
}
public class Client {
public static void main(String[] args) {
SuperStar superStar = new StarProxy(true);
superStar.perform();
superStar = new StarProxy(false);
superStar.perform();
}
}