Facade Pattern
Posted nedrain
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Facade Pattern相关的知识,希望对你有一定的参考价值。
问题
Description
//DVDPlayer.java
public class DVDPlayer {
private static DVDPlayer instance = new DVDPlayer();
public static DVDPlayer getInstance(){
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 PLAY");
}
public void pause(){
System.out.println("DVD PAUSE");
}
}
//Poncorn.java
public class Poncorn {
private static Poncorn instance = new Poncorn();
public static Poncorn getInstance(){
return instance;
}
public void on(){
System.out.println("Popcorn ON");
}
public void off(){
System.out.println("Popcorn OFF");
}
public void pop(){
System.out.println("Popcorn POP");
}
}
// Projection.java
public class Projection {
private static Projection instance = new Projection();
public static Projection getInstance(){
return instance;
}
public void on(){
System.out.println("Projection ON");
}
public void off(){
System.out.println("Projection OFF");
}
public void projection(){
System.out.println("Projection project");
}
}
//Facade.java
public class Facede {
private DVDPlayer dvdPlayer;
private Poncorn poncorn;
private Projection projection;
public Facede(){
this.dvdPlayer = DVDPlayer.getInstance();
this.poncorn = Poncorn.getInstance();
this.projection = Projection.getInstance();
}
public void on(){
dvdPlayer.on();
poncorn.on();
projection.on();
}
public void off(){
dvdPlayer.off();
poncorn.off();
projection.off();
}
public void play(){
dvdPlayer.play();
}
public void pause(){
dvdPlayer.pause();
}
public void pop(){
poncorn.pop();
}
public void projection(){
projection.projection();
}
}
//Client.java
public class Client {
public static void main(String[] args) {
Facede facede = new Facede();
facede.on();
facede.play();
facede.pop();
facede.projection();
facede.off();
}
}
以上是关于Facade Pattern的主要内容,如果未能解决你的问题,请参考以下文章