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

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

代码如下:

定义多个影院设备类:

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

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

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

最新文章

  1. PHP7的安装
  2. Js提示框
  3. 全选Form > Grid 的所有行
  4. grep,awk和sed的常用命令和语法
  5. EBS报表输出文件格式控制
  6. Google AppEngine 创建的例子
  7. WINHTTP的API接口说明。
  8. java 调用oracle 分页存储过程 返回游标数据集
  9. 解决SQL Server的TEXT、IMAGE类型字段的长度限制
  10. 初学Python(八)——迭代
  11. 【LaTeX排版】LaTeX论文排版<四>
  12. Hadoop权限管理
  13. sudo: java 找不到命令
  14. 搜索引擎选择: Elasticsearch与Solr(转)
  15. CodeForces615B-Longtail Hedgehog-dp/图
  16. Qt界面设计基础
  17. Retrofit2 动态(静态)添加请求头Header
  18. 从马文到AlphaGo AI走过了怎样的70年?
  19. 详解使用flask_paginate进行分页
  20. JAVA list集合两种去重方法

热门文章

  1. 动态规划最短路径LintcodeNO110
  2. Go 每日一库之 flag
  3. 你的应用安全吗? ——用Xray和Synk保驾护航
  4. javalite 使用druid数据库连接池配置
  5. Python中函数参数 *args 和 **kwargs
  6. 区间dp - 括号匹配并输出方案
  7. arima.predict()参数选择以及相关的一些问题
  8. Java入门 - 语言基础 - 03.基础语法
  9. python super()函数:调用父类的构造方法
  10. 在eclipse中用java调用python报错 Exception in thread "main" ImportError: Cannot import site module and its dependencies