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
随机推荐
- PHP发送邮件:如何自定义reply-to头部以及附件
虽然有现成的类库(如PEAR)可以很方便地实现附件添加和发送,但是对于一些小站点(服务器硬件.网站规模都不理想),安装PEAR可能会带来不必要的负担,降低WEB程序运行效率. 通过对邮件格式的认识,我 ...
- LSTM及其变种及其克服梯度消失
本宝宝又转了一篇博文,但是真的很好懂啊: 写在前面:知乎上关于lstm能够解决梯度消失的问题的原因: 上面说到,LSTM 是为了解决 RNN 的 Gradient Vanish 的问题所提出的.关于 ...
- linux的fwrite()使用方法,当前时间写入文本的程序
fwrite函数 1.函数功能 用来读写一个数据块. 2.一般调用形式 fwrite(buffer,size,count,fp); 3.说明 (1)buffer:是一个指针,对fread来说,它是读入 ...
- Codeforces 821C Okabe and Boxes(模拟)
题目大意:给你编号为1-n的箱子,放的顺序不定,有n条add指令将箱子放入栈中,有n条remove指令将箱子移除栈,移出去的顺序是从1-n的,至少需要对箱子重新排序几次. 解题思路:可以通过把栈清空表 ...
- cfg 4 ocl
http://blog.sina.com.cn/s/blog_6c868c470102v15y.html rnnlib真难装 http://sourceforge.net/p/rnnl/wiki/Ho ...
- angular.js 验证码注册登录
css部分 header{ height: 50px; line-height: 50px; display: flex; } .callback{ text-align: left; display ...
- 使用OpenSSL自签发服务器https证书
OpenSSL官方推荐win32可执行文件版下载:http://www.slproweb.com/products/Win32OpenSSL.html ca.key CA私钥: openssl gen ...
- 救济金发放(UVa133)
题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...
- Centos bash: make: command not found
一般出现这个bash: make: command not found提示,是因为安装系统的时候使用的是最小化mini安装,系统没有安装make.vim等常用命令,直接yum安装下即可: yum -y ...
- HashMap在Java1.7与1.8中的区别
基于JDK1.7.0_80与JDK1.8.0_66做的分析 JDK1.7中 使用一个Entry数组来存储数据,用key的hashcode取模来决定key会被放到数组里的位置,如果hashcode相同, ...