feat: 外观模式
This commit is contained in:
parent
99b9b86bfa
commit
3ede036009
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
1740
README/设计模式-v2.md
1740
README/设计模式-v2.md
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,51 @@
|
|||
package cn.bunny.pattern10;
|
||||
|
||||
public class Facade {
|
||||
public static void main(String[] args) {
|
||||
DeviceFacade deviceFacade = new DeviceFacade();
|
||||
// 查看
|
||||
deviceFacade.on();
|
||||
|
||||
// 看完关闭
|
||||
deviceFacade.off();
|
||||
}
|
||||
|
||||
// 子系统-手机
|
||||
static class SubSystemIPhone {
|
||||
public void on() {
|
||||
System.out.println("打开手机。。。");
|
||||
}
|
||||
|
||||
public void off() {
|
||||
System.out.println("关闭手机。。。");
|
||||
}
|
||||
}
|
||||
|
||||
// 子系统-天气
|
||||
static class SubSystemWeather {
|
||||
public void on() {
|
||||
System.out.println("打开天气。。。");
|
||||
}
|
||||
|
||||
public void off() {
|
||||
System.out.println("关闭天气。。。");
|
||||
}
|
||||
}
|
||||
|
||||
// 门面
|
||||
static class DeviceFacade {
|
||||
// 也可以作为参数传递,如果没有别的实现类,直接在内部初始化会使使用者更简单
|
||||
SubSystemIPhone subSystemIPhone = new SubSystemIPhone();
|
||||
SubSystemWeather subSystemWeather = new SubSystemWeather();
|
||||
|
||||
public void on() {
|
||||
subSystemIPhone.on();
|
||||
subSystemWeather.on();
|
||||
}
|
||||
|
||||
public void off() {
|
||||
subSystemWeather.off();
|
||||
subSystemIPhone.off();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue