照着写,然后getRegister()方法的具体实现就是:打印一句话,然后到时候是什么方法具体实现就行
package wgms;
public class Register {
public void getRegister(){
System.out.println("挂号成功");
}
}
package wgms;
public class OutpatientService {
public void check(){
System.out.println("小小新冠,危及不到生命,喝上两天Java就好,忠告:小病自我诊断,大病自我了断");
}
}
package wgms;
/*
* 划价
*/
public class Price {
public void showPrice(){
System.out.println("Java每颗¥:100w,共¥:200w");
}
}
package wgms;
/*
* 取药
*/
public class Pharmacy {
public void getMedicine(){
System.out.println("给你两颗Java,赶紧回去吃");
}
}
先照着写,然后方法的具体实现是 : 对象调方法
此时会报空指针异常
只要是控制着异常就是 没有new对象
因为new对象 所以要写构造方法,进行初始化
package wgms;
/*
* facade 外观
*/
public class Facade {
private Register register;//起名字
private OutpatientService ops;
private Price price;
private Pharmacy pharmacy;
public Facade(){
register = new Register();
ops = new OutpatientService();
price = new Price();
pharmacy = new Pharmacy();
}
public void seeDoctor(){
register.getRegister();
ops.check();
price.showPrice();
pharmacy.getMedicine();
}
}
test方法就是 :new facade 对象,然后 对象打点调方法
package wgms;
public class Test {
public static void main(String[] args) {
Facade f = new Facade();
f.seeDoctor(); }
}