java: Facade Pattern

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 * 版权所有 2022 涂聚文有限公司
 * 许可信息查看:
 * 描述:
 * 门面模式 Facade Patterns
 * 历史版本: JDK 14.02
 * 2022-09-12 创建者 geovindu
 * 2022-09-12 添加 Lambda
 * 2022-09-12 修改:date
 * 接口类
 * 2022-09-12 修改者:Geovin Du
 * 生成API帮助文档的指令:
 *javadoc - -encoding Utf-8 -d apidoc Camera.java
 *
 * */
 
 
 
package com.javapatterns.facade;
 
/**
 *录像
 * @author geovindu  Geovin Du 涂聚文
 *
 * */
public class Camera {
 
 
    /*
    public  Camera()
    {
 
    }*/
    /**
     *
     *打开录像机
     * */
    public void turnOn()
    {
        System.out.println("Turning on the camera.");
    }
    /**
     *关闭录像机
     *
     * */
    public void turnOff()
    {
        System.out.println("Turning off the camera.");
    }
    /**
     *转动录像机
     *
     * */
    public void rotate(int degrees)
    {
        System.out.println("Rotating the camera by " + degrees + " degrees.");
    }
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
 * 版权所有 2022 涂聚文有限公司
 * 许可信息查看:
 * 描述:
 * 门面模式 Facade Patterns
 * 历史版本: JDK 14.02
 * 2022-09-12 创建者 geovindu
 * 2022-09-12 添加 Lambda
 * 2022-09-12 修改:date
 * 接口类
 * 2022-09-12 修改者:Geovin Du
 * 生成API帮助文档的指令:
 *javadoc - -encoding Utf-8 -d apidoc Alarm.java
 *
 * */
 
 
package com.javapatterns.facade;
/**
 *警报器
 * @author geovindu   Geovin Du 涂聚文
 * */
public class Alarm {
 
 
   /*
    public  Alarm()
    {
 
    }
*/
 
    /**
     *启动警报器
     *
     * */
    public void activate()
    {
        System.out.println("Activating the alarm.");
    }
    /**
     *关闭警报器
     *
     * */
    public void deactivate()
    {
        System.out.println("Deactivating the alarm.");
    }
    /**
     *拉响警报器
     *
     * */
    public void ring()
    {
        System.out.println("Ring the alarm.");
    }
    /**
     *停掉警报器
     *
     * */
    public void stopRing()
    {
        System.out.println("Stop the alarm.");
    }
 
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
 * 版权所有 2022 涂聚文有限公司
 * 许可信息查看:
 * 描述:
 * 门面模式 Facade Patterns
 * 历史版本: JDK 14.02
 * 2022-09-12 创建者 geovindu
 * 2022-09-12 添加 Lambda
 * 2022-09-12 修改:date
 * 接口类
 * 2022-09-12 修改者:Geovin Du
 * 生成API帮助文档的指令:
 *javadoc - -encoding Utf-8 -d apidoc Light.java
 *
 * */
 
package com.javapatterns.facade;
/**
 *灯
 * @author geovindu   Geovin Du 涂聚文
 * */
public class Light {
 
/*
    public  Light()
    {
 
    }*/
    /**
     *打开灯
     *
     * */
    public void turnOn()
    {
        System.out.println("Turning on the light.");
    }
    /**
     *关闭灯
     *
     * */
    public void turnOff()
    {
        System.out.println("Turning off the light.");
    }
    /**
     *换灯泡
     *
     * */
    public void changeBulb()
    {
        System.out.println("Changing the light-bulb.");
    }
 
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
 * 版权所有 2022 涂聚文有限公司
 * 许可信息查看:
 * 描述:
 * 门面模式 Facade Patterns
 * 历史版本: JDK 14.02
 * 2022-09-12 创建者 geovindu
 * 2022-09-12 添加 Lambda
 * 2022-09-12 修改:date
 * 接口类
 * 2022-09-12 修改者:Geovin Du
 * 生成API帮助文档的指令:
 *javadoc - -encoding Utf-8 -d apidoc Sensor.java
 *
 * */
 
package com.javapatterns.facade;
/**
 *感应器
 * @author geovindu   Geovin Du 涂聚文
 * */
public class Sensor {
 
 
/*
    public  Sensor()
    {
 
    }*/
    /**
     *启动感应器
     *
     * */
    public void activate()
    {
        System.out.println("Activating on the sensor.");
    }
    /**
     *关闭感应滴
     *
     * */
    public void deactivate()
    {
        System.out.println("Deactivating on the sensor.");
    }
    /**
     *触发感应器
     *
     * */
    public void trigger()
    {
        System.out.println("The sensor has been triggered.");
    }
 
}

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
 * 版权所有 2022 涂聚文有限公司
 * 许可信息查看:
 * 描述:
 * 门面模式  外观模式 Facade Patterns
 * 历史版本: JDK 14.02
 * 2022-09-12 创建者 geovindu
 * 2022-09-12 添加 Lambda
 * 2022-09-12 修改:date
 * 接口类
 * 2022-09-12 修改者:Geovin Du
 * 生成API帮助文档的指令:
 *javadoc - -encoding Utf-8 -d apidoc SecurityFacade.java
 *
 * */
 
package com.javapatterns.facade;
/**
 *门面类
 * @author geovindu   Geovin Du 涂聚文
 * */
public class SecurityFacade {
 
    /**
     * @directed*/
    private Camera camera1, camera2;
 
    /**
     * @directed
     */
    private Light light1, light2, light3;
 
    /**
     * @directed*/
    private Sensor sensor;
 
    /**
     * @directed*/
    private Alarm alarm;
    /**
     *构造
     *
     * */
     public  SecurityFacade()
     {
         camera1=new Camera();
         camera2=new Camera();
         light1=new Light();
         light2=new Light();
         light3=new Light();
         sensor=new Sensor();
         alarm=new Alarm();
     }
    /**
     *启动
     *
     * */
    public void activate()
    {
        camera1.turnOn();
        camera2.turnOn();
 
        light1.turnOn();
        light2.turnOn();
        light3.turnOn();
 
        sensor.activate();
 
        alarm.activate();
    }
    /**
     *关闭
     *
     * */
    public void deactivate()
    {
        camera1.turnOff();
        camera2.turnOff();
 
        light1.turnOff();
        light2.turnOff();
        light3.turnOff();
 
        sensor.deactivate();
 
        alarm.deactivate();
    }
 
 
}

  

调用测试:

1
2
3
//门面模式
security=new SecurityFacade();
security.activate();

  

输出:

1
2
3
4
5
6
7
Turning on the camera.
Turning on the camera.
Turning on the light.
Turning on the light.
Turning on the light.
Activating on the sensor.
Activating the alarm.

  

 

 

posted @   ®Geovin Du Dream Park™  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2018-09-19 MySQL5.7: sql script demo
2011-09-19 sql uniqueidentifier转换成varchar 数据类型
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示