feat: 外观模式

This commit is contained in:
Bunny 2025-02-03 16:25:11 +08:00
parent 99b9b86bfa
commit 3ede036009
3 changed files with 962 additions and 823 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

File diff suppressed because it is too large Load Diff

View File

@ -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();
}
}
}