head first---------facade design pattern
import org.omg.CORBA.TCKind;
/**
* 功放、扩音器类
* @author Administrator
*
*/
public class Amplifier {
public void on(){
System.out.println("打开功放....");
}
public void off(){
System.out.println("关闭功放....");
}
//设置是DVD还是VCD播放模式
public void setPlayerModel(TvPlayerModel tvPlayerModel){
tvPlayerModel.setModel();
}
public void setSurroundSound(TvPlayerModel tvPlayerModel){
tvPlayerModel.setVoiceType();
}
//音量大小
public void setVoiceLevel(int voice){
System.out.println("音量大小为:"+voice);
}
}
/**
* DVD 播放
* @author Administrator
*
*/
public class DvdPlayerModel implements TvPlayerModel{
@Override
public void setModel() {
System.out.println("播放模式是DVD....");
}
public void on(){
System.out.println("打开Dvd player...");
}
public void off(){
System.out.println("关闭dvd player....");
}
public void play(String movie){
System.out.println("dvd 播放...."+movie);
}
public void setVoiceType(){
System.out.println("声音为立体声....");
}
public void setTwoChannelAudio(){
System.out.println("设置两个频道自动播放....");
}
public void pause(){
System.out.println("暂停....");
}
public void stop(){
System.out.println("停止播放....");
}
}
/**
* 组装家庭影院的类,包括watchMovie(String type)
* endMovie()方法
* @author Administrator
*
*/
public class HomeTheaterFacade {
public Amplifier amplifier;
public Tuner tuner;
public TvPlayerModel tvModel;
public Projector projector;
public TheaterLight lights;
public Screen screen;
public PopCornPopper popper;
public HomeTheaterFacade(Amplifier amplifier, Tuner tuner,
TvPlayerModel tvModel, Projector projector, TheaterLight lights,
Screen screen, PopCornPopper popper) {
this.amplifier = amplifier;
this.tuner = tuner;
this.tvModel = tvModel;
this.projector = projector;
this.lights = lights;
this.screen = screen;
this.popper = popper;
}
//encapsulation watch movie
public void watchMovie(String movie){
System.out.println("Get ready to watch a movie......");
popper.on();
popper.pop();
lights.dim(10);
screen.down();
projector.on();
projector.setWidenScreenModel();
amplifier.on();
amplifier.setPlayerModel(tvModel);
amplifier.setSurroundSound(tvModel);
amplifier.setVoiceLevel(5);
tvModel.on();
tvModel.play(movie);
}
//close movie
public void endMovie(){
System.out.println("Shutting movie theater down.....");
popper.off();
lights.off();
screen.up();
projector.off();
amplifier.off();
tvModel.stop();
tvModel.off();
}
}
/**
* 观赏电影
* @author Administrator
*
*/
public class HomeTheaterTest {
public static void main(String[] args) {
//实例化组件
Amplifier amplifier=new Amplifier();
Tuner tuner=new Tuner();
TvPlayerModel tvModel=new DvdPlayerModel();
Projector projector=new Projector();
Screen screen=new Screen();
TheaterLight lights=new TheaterLight();
PopCornPopper popCornPopper=new PopCornPopper();
HomeTheaterFacade homeTheater=new HomeTheaterFacade(amplifier, tuner, tvModel, projector, lights, screen, popCornPopper);
homeTheater.watchMovie("火线三兄弟...........");
homeTheater.endMovie();
}
}
/**
* 爆米花类
* @author Administrator
*
*/
public class PopCornPopper {
public void on(){
System.out.println("打开爆米花机......");
}
public void off(){
System.out.println("关闭爆米花机......");
}
public void pop(){
System.out.println("开始爆米花机......");
}
}
/**
* 投影仪
* @author Administrator
*
*/
public class Projector {
//set player on model
public void setWidenScreenModel(){
System.out.println("projecor model is widen....");
}
public void on(){
System.out.println("打开投影仪....");
}
public void off(){
System.out.println("关闭投影仪...");
}
//设置投影仪模式
public void setTvModel(TvPlayerModel tvModel){
tvModel.setModel();
}
}
/**
* 屏幕类
* @author Administrator
*
*/
public class Screen {
public void down(){
System.out.println("把屏幕放下...");
}
public void up(){
System.out.println("把屏幕拉上...");
}
}
/**
* 电影院的类
* @author Administrator
*
*/
public class TheaterLight {
public void on(){
System.out.println("打开电影院....");
}
public void off(){
System.out.println("关闭电影院....");
}
public void dim(int volumn){
System.out.println("灯光亮度是原来的"+volumn+"%");
}
}
/**
* 收音机类
* @author Administrator
*
*/
public class Tuner {
public void on(){
System.out.println("打开tuner...");
}
public void off(){
System.out.println("关闭tuner...");
}
public void setAm(){
System.out.println("跳到 am 频道...");
}
public void setFm(){
System.out.println("跳到 fm 频道....");
}
}
/**
* 播放模式,DVD、VCD
* @author Administrator
*
*/
public interface TvPlayerModel {
public void setModel();
public void setVoiceType();//声道种类
public void on();
public void off();
public void play(String movie);
public void setTwoChannelAudio();
public void pause();
public void stop();
}
/**
* VCD 播放
* @author Administrator
*
*/
public class VcdPlayer implements TvPlayerModel{
@Override
public void setModel() {
System.out.println("播放模式是VCD....");
}
public void on(){
System.out.println("打开vcd player...");
}
public void off(){
System.out.println("关闭vcd player....");
}
public void play(String movie){
System.out.println("vcd 播放...."+movie);
}
public void setVoiceType(){
System.out.println("声音为立体声....");
}
public void setTwoChannelAudio(){
System.out.println("设置两个频道自动播放....");
}
public void pause(){
System.out.println("暂停....");
}
public void stop(){
System.out.println("停止播放....");
}
}
打开爆米花机......
开始爆米花机......
灯光亮度是原来的10%
把屏幕放下...
打开投影仪....
projecor model is widen....
打开功放....
播放模式是DVD....
声音为立体声....
音量大小为:5
打开Dvd player...
dvd 播放....火线三兄弟...........
Shutting movie theater down.....
关闭爆米花机......
关闭电影院....
把屏幕拉上...
关闭投影仪...
关闭功放....
停止播放....
关闭dvd player....
head first---------facade design pattern的更多相关文章
- 设计模式之 - 外观模式 (Facade design pattern)
1. 模式意图: 为子系统中的一组接口提供一个一致的界面,Facade模式定义了一个高层接口,这个接口使得这一子系统更容易使用. 2. 结构 3. 工厂方法模式C#实现 using System; ...
- 说说设计模式~大话目录(Design Pattern)
回到占占推荐博客索引 设计模式(Design pattern)与其它知识不同,它没有华丽的外表,没有吸引人的工具去实现,它是一种心法,一种内功,如果你希望在软件开发领域有一种新的突破,一个质的飞越,那 ...
- 设计模式(Design Pattern)系列之.NET专题
最近,不是特别忙,重新翻了下设计模式,特地在此记录一下.会不定期更新本系列专题文章. 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结. 使用 ...
- [转]Design Pattern Interview Questions - Part 4
Bridge Pattern, Composite Pattern, Decorator Pattern, Facade Pattern, COR Pattern, Proxy Pattern, te ...
- Design Pattern in Simple Examples
Instead of defining what is design pattern lets define what we mean by design and what we mean by pa ...
- java设计模式大全 Design pattern samples in Java(最经典最全的资料)
java设计模式大全 Design pattern samples in Java(最经典最全的资料) 2015年06月19日 13:10:58 阅读数:11100 Design pattern sa ...
- [转]Design Pattern Interview Questions - Part 2
Interpeter , Iterator , Mediator , Memento and Observer design patterns. (I) what is Interpreter pat ...
- [转]Design Pattern Interview Questions - Part 3
State, Stratergy, Visitor Adapter and fly weight design pattern from interview perspective. (I) Can ...
- [转]Design Pattern Interview Questions - Part 1
Factory, Abstract factory, prototype pattern (B) What are design patterns? (A) Can you explain facto ...
- design pattern
1. visitor design pattern http://butunclebob.com/ArticleS.UncleBob.IuseVisitor
随机推荐
- mysql的两种存储引擎
MySQL 有多种存储引擎,目前常用的是 MyISAM 和 InnoDB 这两个引擎,除了这两个引擎以为还有许多其他引擎,有官方的,也有一些公司自己研发的.这篇文章主要简单概述一下常用常见的 MySQ ...
- csu 1598(KMP)
1598: 最长公共前缀 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 109 Solved: 92[Submit][Status][Web Boar ...
- 简易web-slide
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 开始学习MaxCompute
https://help.aliyun.com/document_detail/34615.html?spm=a2c4g.11186623.6.688.jVxTMW
- Mysql学习之order by的工作原理
在你开发应用的时候,一定会经常碰到需要根据指定的字段排序来显示结果的需求.假设你要查询城市是“杭州”的所有人名字,并且按照姓名排序返回前 1000 个人的姓名.年龄. 查询语句为: ; 全字段排序 为 ...
- js学习笔记1:语法、数据类型与转换、运算符与运算
注意: 上部代码错误,将停止运行,下部的代码无法显示 typeof 用来定义内容类型,不会输出内容只会输出类型 一.js输出语法 1. 弹窗输出('')内的内容: ...
- HTK训练错误消息意义
在HTK训练线上数据的时候,遇到了ERROR [+6550] LoadHTKLabels: Junk at end of HTK transcription,这个问题,网上查阅是说有空行,结果根本没有 ...
- [实战]MVC5+EF6+MySql企业网盘实战(13)——编辑文件夹
写在前面 上篇文章实现了,新建文件夹以及与之前的上传文件的逻辑做了集成,本篇文章将实现编辑文件夹名称,其实这个也有难点,就是编辑文件夹名称时,要考虑文件夹中存在文件或者子文件夹的情况,因为他们的路径已 ...
- run-time setting 中设置simulate browser cache 选项详解
Browser Emulation: Simulate browser cache:配置Vuser模拟带缓存的浏览器.缺省缓存是被允许的, 可以通过禁止该选项来使得所有VUser模拟的浏览器都不 ...
- mysql字符编码相关
mysql> show variables like '%character%'; +--------------------------+--------------------------- ...