您的位置:首页 > 其它

设计模式之外观模式

2016-03-23 15:37 459 查看
外观模式是通过对一个复杂的类的所包含的类进行封装,通过连接作用实现调用.也实现了降低许多类的之间的耦合度.

public class Mouse {
private String wheel;
public Mouse(){}
public Mouse(String wheel) {
this.wheel = wheel;
System.out.println("组装鼠标");
}
}
public class Keyboard {
private String keypad;
public Keyboard(){}
public Keyboard(String keypad) {
this.keypad = keypad;
System.out.println("组装键盘");
}
}
将两者的相关属性放到一个类中包含

public class Computer {
private Mouse mouse;
private Keyboard keyboard;
public Computer() {
mouse = new Mouse("鼠标");
keyboard = new Keyboard("键盘");
System.out.println("电脑组装");
}
}
主函数测试:

public class Main {
public static void main(String[] args) {
Computer computer = new Computer();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: