码迷,mamicode.com
首页 > 其他好文 > 详细

Facade Pattern

时间:2020-06-27 20:21:00      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:oid   desc   pattern   esc   use   layer   load   play   lang   

问题

技术图片


技术图片

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

标签:oid   desc   pattern   esc   use   layer   load   play   lang   

原文地址:https://www.cnblogs.com/nedrain/p/13199308.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!