
/**
* 版权所有 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.");
}
}/**
* 版权所有 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.");
}
}/**
* 版权所有 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.");
}
}/**
* 版权所有 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.");
}
}/**
* 版权所有 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();
}
}调用测试:
//门面模式
security=new SecurityFacade();
security.activate();输出:
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.