外观模式隐藏了系统的的复杂性,为客户端提供一个可以访问系统的接口,由接口决定访问系统的哪些功能,以及怎么访问,客户端可以完全不了解系统的内部情况,方便系统的内部拓展和维护。示例如下:
public class Exterior {
public static void main(String[] args){
Exterior exterior = new Exterior();
Receptionist receptionist0=exterior.new Receptionist("没病多疑");
receptionist0.noDisease();
Receptionist receptionist1=exterior.new Receptionist("小病");
receptionist1.lightDisease();
Receptionist receptionist2=exterior.new Receptionist("重病");
receptionist2.weightyDisease();
}
class Outpatient{
public void work(){
System.out.println("门诊");
}
}
class Register{
public void work(){
System.out.println("挂号");
}
}
class Payment{
public void work(){
System.out.println("缴费");
}
}
class Medicine{
public void work(){
System.out.println("取药");
}
}
class Surgery{
public void work(){
System.out.println("手术");
}
}
class Receptionist{
private Register register;
private Outpatient outpatient;
private Payment payment;
private Medicine medicine;
private Surgery surgery;
private String type;
public Receptionist(String type) {
this.type = type;
register=new Register();
outpatient=new Outpatient();
payment=new Payment();
medicine=new Medicine();
surgery=new Surgery();
}
public void noDisease(){
showType();
register.work();
outpatient.work();
}
public void lightDisease(){
showType();
register.work();
outpatient.work();
payment.work();
medicine.work();
}
public void weightyDisease(){
showType();
register.work();
outpatient.work();
payment.work();
medicine.work();
surgery.work();
}
private void showType(){
System.out.println(type);
}
}
}
网友评论