现在的位置: 首页 > 综合 > 正文

设计模式-结构型模式-外观

2017年12月08日 ⁄ 综合 ⁄ 共 627字 ⁄ 字号 评论关闭

结构型模式:结构型对象模式不是对接口或实现进行组合的.而是描述了如何对一些对象进行组合,从而实现新功能的一些方法.
facade模式:为子系统中的一组接口提供一个一致的界面,定义了一个高层的接口,这个接口使子系统更加容易的使用.

package structure.facade;
/**
 *  A very simple test
 */
import java.io.*;

class Wall {
    public Wall() {
        System.out.println("Create a wall !");
    }
}

class Door {
    public Door() {
        System.out.println("Create a door !");
    }
}

class FacadeRoom {
    public void CreateRoom() {
        Wall wall1 = new Wall();
        Wall wall2 = new Wall();
        Wall wall3 = new Wall();
        Wall wall4 = new Wall();
        Door door = new Door();
    }

}

public class Test  {
    public static void main(String[] args) {
        FacadeRoom room = new FacadeRoom();
        room.CreateRoom();
    }
}

抱歉!评论已关闭.