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
随机推荐
- fedora16下更改网卡名字
fedora16下更改网卡名字 今天由于网络启动出错的原因,在网上搜索,发现大部分人的网卡名字都是eth0,可是我的却是p3p1,所以想改成eth0. 然后google了下,发现设备命名什么的 ...
- leetcode 之Search in Rotated Sorted Array(三)
描述 Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 ...
- HDU 1560 DNA sequence(IDA*)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1560 题目大意:给出n个字符串,让你找一个字符串使得这n个字符串都是它的子串,求最小长度. 解题思路: ...
- EF – 8.多对多关联
5.6.10 <多对多关联(上)> 时长:9分57秒 难度:难 5.6.11<多对多关联(下)> 时长:8分50秒 难度:难 如果单独地把多对多关联的CRUD拿出来讲,确实比较 ...
- c++ primer 9 顺序容器
定义: #include <vector> #include <list> #include <deque> vector<int> svec; lis ...
- loadrunner获取毫秒及字符串替换实现
loadrunner获取毫秒及字符串替换实现 今天做一个性能测试,参数化要求创建用户名不可以重复,想来想不没有什么好的办法来避免用户名字的重复.所以就想用时间+随机数来实现,但是实现中遇到一个问题. ...
- spring_150901_hibernate_transaction_xml
实体类: package com.spring.model; import javax.persistence.Entity; import javax.persistence.Id; import ...
- springMVC
SpringMVC架构流程: 1.用户发送请求至前端控制器DispatcherServlet2.DispatcherServlet收到请求调用HandlerMapping处理器映射器.3.处理器映射器 ...
- FastReport.Net使用:[26]数字格式
1.数据包含固定格式的小数,自由格式的小数,以及字符串格式等四列数据.包含3行数据(1.2,1.23,1.234). 以下为Access数据视图和FastReport.Net报表设计器中的数据视图. ...
- poj 2096Collecting Bugs
题目链接 poj 2096Collecting Bugs 题解 dp[i][j]表示已经找到i种bug,并存在于j个子系统中,要达到目标状态的天数的期望. 显然,dp[n][s]=0,因为已经达到目标 ...