假设家庭影院有一系列设备,每个设备都有各种开闭等功能性方法,使用家庭影院功能的时候,需要进行各个设备的一系列操作,繁琐麻烦。

现在提供一个外观类,在里面定义操作流程,客户端只需要和外观类进行接口交互即可,不用管 具体的操作流程。

代码如下:

定义多个影院设备类:

public class DVDPlayer {

	private static DVDPlayer instance = new DVDPlayer();

	public static DVDPlayer getInstanc() {
		return instance;
	}

	public void on() {
		System.out.println(" dvd on ");
	}
	public void off() {
		System.out.println(" dvd off ");
	}

	public void play() {
		System.out.println(" dvd is playing ");
	}

	//....
	public void pause() {
		System.out.println(" dvd pause ..");
	}
}

  

public class Popcorn {

	private static Popcorn instance = new Popcorn();

	public static Popcorn getInstance() {
		return instance;
	}

	public void on() {
		System.out.println(" popcorn on ");
	}

	public void off() {
		System.out.println(" popcorn ff ");
	}

	public void pop() {
		System.out.println(" popcorn is poping  ");
	}
}

  

public class Projector {

	private static Projector instance = new Projector();

	public static Projector getInstance() {
		return instance;
	}

	public void on() {
		System.out.println(" Projector on ");
	}

	public void off() {
		System.out.println(" Projector ff ");
	}

	public void focus() {
		System.out.println(" Projector is Projector  ");
	}

	//...
}

  

public class Screen {

	private static Screen instance = new Screen();

	public static Screen getInstance() {
		return instance;
	}

	public void up() {
		System.out.println(" Screen up ");
	}

	public void down() {
		System.out.println(" Screen down ");
	}

}

  

public class Stereo {

	private static Stereo instance = new Stereo();

	public static Stereo getInstance() {
		return instance;
	}

	public void on() {
		System.out.println(" Stereo on ");
	}

	public void off() {
		System.out.println(" Screen off ");
	}

	public void up() {
		System.out.println(" Screen up.. ");
	}

	//...
}

  

public class TheaterLight {

	private static TheaterLight instance = new TheaterLight();

	public static TheaterLight getInstance() {
		return instance;
	}

	public void on() {
		System.out.println(" TheaterLight on ");
	}

	public void off() {
		System.out.println(" TheaterLight off ");
	}

	public void dim() {
		System.out.println(" TheaterLight dim.. ");
	}

	public void bright() {
		System.out.println(" TheaterLight bright.. ");
	}
}

  

创建外观类:

public class HomeTheaterFacade {

	//定义影院系统 各个子系统模块对象
	private TheaterLight theaterLight;
	private Popcorn popcorn;
	private Stereo stereo;
	private Projector projector;
	private Screen screen;
	private DVDPlayer dVDPlayer;
	//构造器
	public HomeTheaterFacade() {
		super();
		this.theaterLight = TheaterLight.getInstance();
		this.popcorn = Popcorn.getInstance();
		this.stereo = Stereo.getInstance();
		this.projector = Projector.getInstance();
		this.screen = Screen.getInstance();
		this.dVDPlayer = DVDPlayer.getInstanc();
	}
	//操作分为四部

	public void ready() {
		popcorn.on();
		popcorn.pop();
		screen.down();
		projector.on();
		stereo.on();
		dVDPlayer.on();
		theaterLight.dim();
	}
	public void play() {
		dVDPlayer.play();
	}
	public void pause() {
		dVDPlayer.pause();
	}
	public void end() {
		popcorn.off();
		theaterLight.bright();
		screen.up();
		projector.off();
		stereo.off();
		dVDPlayer.off();
	}
}

  测试:

	public static void main(String[] args) {
		HomeTheaterFacade homeTheaterFacade = new HomeTheaterFacade();
		homeTheaterFacade.ready();
		homeTheaterFacade.play();

		homeTheaterFacade.end();
	}

====================================================

  ----------------------------------------------------------------------------------------------------------------------------------------

num13---外观模式/过程模式的更多相关文章

  1. 外观模式 门面模式 Facade 结构型 设计模式(十三)

    外观模式(FACADE) 又称为门面模式   意图 为子系统中的一组接口提供一个一致的界面 Facade模式定义了一个高层接口,这一接口使得这一子系统更加易于使用. 意图解析 随着项目的持续发展,系统 ...

  2. 设计模式在实际业务应用中的介绍之3——外观或门面模式Facade对AOP装配业务工厂的应用

    在C#中实现的基于外观或门面模式打造的业务应用案例 以前一直没有想过写一些东西来把项目中用到的知识点及技术实现做一个归纳整理并分享出来.现在打算逐渐的把项目中的一些东西整理并分享出来,与大家共勉! 外 ...

  3. Facade外观模式(结构性模式)

    1.系统的复杂度 需求:开发一个坦克模拟系统用于模拟坦克车在各种作战环境中的行为,其中坦克系统由引擎.控制器.车轮等各子系统构成.然后由对应的子系统调用. 常规的设计如下: #region 坦克系统组 ...

  4. Handler+ExecutorService(线程池)+MessageQueue模式+缓存模式

    android线程池的理解,晚上在家无事 预习了一下android异步加载的例子,也学习到了一个很重要的东东 那就是线程池+缓存  下面看他们的理解.[size=1.8em]Handler+Runna ...

  5. 【转】Handler+ExecutorService(线程池)+MessageQueue模式+缓存模式

    http://www.cnblogs.com/wanqieddy/archive/2013/09/06/3305482.html android线程池的理解,晚上在家无事 预习了一下android异步 ...

  6. 【转】[Android实例] Handler+ExecutorService(线程池)+MessageQueue模式+缓存模式

    android线程池的理解,晚上在家无事 预习了一下android异步加载的例子,也学习到了一个很重要的东东 那就是线程池+缓存  下面看他们的理解. [size=1.8em]Handler+Runn ...

  7. 工厂模式&策略模式。

    抽象.封装,具体事情做得越多,越容易犯错误.这每个做过具体工作的人都深有体会,相反,官做得越高,说出的话越抽象越笼统,犯错误可能性就越少.好象我们从编程序中也能悟出人生道理.(百度百科) 不断抽象封装 ...

  8. [Android实例] Handler+ExecutorService(线程池)+MessageQueue模式+缓存模式

    android线程池的理解,晚上在家无事 预习了一下android异步加载的例子,也学习到了一个很重要的东东 那就是线程池+缓存  下面看他们的理解. [size=1.8em]Handler+Runn ...

  9. [19/04/24-星期三] GOF23_创建型模式(建造者模式、原型模式)

    一.建造者模式 本质:分离了对象子组件的单独构造(由Builder负责)和装配的分离(由Director负责),从而可以构建出复杂的对象,这个模式适用于:某个对象的构建过程十分复杂 好处:由于构建和装 ...

随机推荐

  1. 源码详解系列(六) ------ 全面讲解druid的使用和源码

    简介 druid是用于创建和管理连接,利用"池"的方式复用连接减少资源开销,和其他数据源一样,也具有连接数控制.连接可靠性测试.连接泄露控制.缓存语句等功能,另外,druid还扩展 ...

  2. .Net Core使用分布式缓存Redis:Lua脚本

    一.前言 运行环境window,redis版本3.2.1.此处暂不对Lua进行详细讲解,只从Redis的方面讲解. 二.Redis的Lua脚本 在Redis的2.6版本推出了脚本功能,允许开发者使用L ...

  3. k8s内运行ubuntu容器

    k8s内运行ubuntu镜像 环境 互相能访问的4台机器master,node01,node02,node03,4核心,内存8G 使用root操作 安装k8s 在master安装docker.kube ...

  4. python条件判断语句

    # 条件判断(if)语句: # 语法1: if 条件表达式 : 单行语句 # 语法2: if 条件表达式 : # 代码块(多行语句) # 执行的流程:if语句在执行时,会先对条件表达式进行求值判断, ...

  5. 安装Mysql 8.0的艰难体验

    背景: Mysql 8.0 以后版本,在性能等方面有了很大提升,而且在自动编号.Timestamp等字段的设置上有了很方便的进步,因此在一年前即开始将原有的基于5.5版本的服务器逐渐向8.0转移.但转 ...

  6. async-await 线程分析

    这里没有线程 原文地址:https://blog.stephencleary.com/2013/11/there-is-no-thread.html 前言 我是在看 C#8.0 新特性异步流时在评论里 ...

  7. java: integer number is too large

    今天想定义一个类常量,结果如下面那样定义,确报错了.error is: Integer number too large public static final Long STARTTIME = 14 ...

  8. kubernetes concepts (一)

    Concepts The Concepts section helps you learn about the parts of the Kubernetes system and the abstr ...

  9. 13.系统总结static

    static修饰属性和方法: package com.oop.demo08; //static :被static修饰的变量或者方法随类加载,从属于类,当然对象也可以调用 public class St ...

  10. spring boot的日常配置

    配置篇 #数据库连接配置msql spring.datasource.url:jdbc:mysql://127.0.0.1:3306/test spring.datasource.username: ...