设计模式(12)--外观模式
来源:互联网 发布:简单的ps软件 编辑:程序博客网 时间:2024/06/08 18:40
什么是外观模式?
隐藏系统的复杂性,并向客户端提供了一个客户端可以访问系统的接口。这种类型的设计模式属于结构型模式,它向现有的系统添加一个接口,来隐藏系统的复杂性。
如何实现?
public interface Shape{ void draw();}
public class Circle implements Shape { public void draw() { System.out.println("Shape: Circle"); }}
public class Rectangle implements Shape { public void draw() { System.out.println("Shape: Rectangle"); }}
外观模式实现:
public class ShapeMaker { private Circle circle; private Rectangle rectangle; public ShapeMaker(){ circle = new Circle(); rectangle = new Rectangle(); } public void drawCircle(){ circle.draw(); } public void drawRectangle(){ rectangle.draw(); }}
调用客户端:
public class Client { public static void main(String[] agrs){ ShapeMaker maker = new ShapeMaker(); maker.drawCircle(); maker.drawRectangle(); }}
阅读全文
0 0
- 设计模式(12)--外观模式
- 设计模式:12 外观模式
- 设计模式(12)-外观模式
- java设计模式12_门面模式(外观模式)
- 设计模式(适配器模式,外观模式)
- 设计模式--外观模式
- 设计模式-外观模式
- 设计模式:外观模式
- 设计模式----外观模式
- 设计模式------外观模式
- 设计模式 外观模式
- 设计模式-【外观模式】
- 设计模式-----外观模式
- 设计模式 - 外观模式
- 设计模式 - 外观模式
- 设计模式- 外观模式
- 设计模式-外观模式
- 设计模式 - 外观模式
- 自定义注解设置缓存有效期的正确姿势
- jvm参数调优
- 关于使用chrome扩展插件
- IFE-TASK17(任务十七:零基础JavaScript编码(五))
- Matlab GUI,进度条(waitbar)
- 设计模式(12)--外观模式
- connector.ClientAbortException: java.io.IOException: 您的主机中的软件中止了一个已建立的连接
- py 查看一个文件夹下的文件数量
- Java细节与规范:ArrayList为何建议赋予默认值及其扩容机制
- SPOJFTOUR2-Free tour II
- TensorFlow:NameError: name ‘input_data’ is not defined
- java开发必会技能
- [Linux--Shell]linux下tree命令详解
- typeof、offsetof、container_of的解释