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的主要内容,如果未能解决你的问题,请参考以下文章

外观/门面模式(Facade Pattern)

设计模式之- 外观模式(Facade Pattern)

10.外观模式(Facade Pattern)

Facade Pattern

外观模式(Facade Pattern)

javascript [Design Patterns - Facade Pattern]