设计模式 - 结构型模式 - 装饰模式
来源:互联网 发布:科幻小说 知乎 编辑:程序博客网 时间:2024/05/16 12:07
//抽象界面构件类:抽象构件类,为了突出与模式相关的核心代码,对原有控件代码进行了大量的简化abstract class Component { public abstract void display();}//窗体类:具体构件类class Window extends Component { public void display() { System.out.println("显示窗体!"); }}//文本框类:具体构件类class TextBox extends Component { public void display() { System.out.println("显示文本框!"); }}//列表框类:具体构件类class ListBox extends Component { public void display() { System.out.println("显示列表框!"); }}//构件装饰类:抽象装饰类class ComponentDecorator extends Component { private Component component; //维持对抽象构件类型对象的引用 public ComponentDecorator(Component component) //注入抽象构件类型的对象 { this.component = component; } public void display() { component.display(); }}//滚动条装饰类:具体装饰类class ScrollBarDecorator extends ComponentDecorator { public ScrollBarDecorator(Component component) { super(component); } public void display() { this.setScrollBar(); super.display(); } public void setScrollBar() { System.out.println("为构件增加滚动条!"); }}//黑色边框装饰类:具体装饰类class BlackBorderDecorator extends ComponentDecorator { public BlackBorderDecorator(Component component) { super(component); } public void display() { this.setBlackBorder(); super.display(); } public void setBlackBorder() { System.out.println("为构件增加黑色边框!"); }}class Client { public static void main(String args[]) { Component component, componentSB; //使用抽象构件定义 component = new Window(); //定义具体构件 componentSB = new ScrollBarDecorator(component); //定义装饰后的构件 componentSB.display(); }}
0 0
- 设计模式 - 结构型模式 - 装饰模式
- 设计模式-结构型-装饰
- 设计模式-结构型模式-装饰
- 设计模式--结构型--装饰模式
- 设计模式9:装饰模式【结构型】
- [设计模式-结构型]装饰模式(Decorator)
- 设计模式-结构型之装饰模式
- 结构型设计模式-装饰模式
- 结构型设计模式-装饰器模式
- 设计模式 结构型设计模式之装饰模式
- 设计模式--结构模式--装饰模式--Java
- 结构型设计模式---Decorator模式(装饰模式)
- 设计模式中结构型模式(四)装饰模式(Decorator)
- (C++设计模式) ------Decorator装饰模式-- 结构型模式
- 设计模式_结构型模式_装饰模式
- java设计模式之结构型模式-装饰模式
- 设计模式-结构型模式:装饰器模式 Decorator
- 设计模式深入学习---Decorator装饰模式(结构型模式)
- Java 生成二维码
- WinSock网络通信
- Oracle UTL_RAW
- 内置晶体RTC的优势分析
- Spring MVC Controller配置方式
- 设计模式 - 结构型模式 - 装饰模式
- Oracle系统权限的分类
- 将{"result": [ { "Name1":"data1" , "Name2":"data2" }]}转成添加到map集合
- windows 10 及 windows server 2012 中vnc不显示鼠标光标的问题解决
- java利器jodd打印输出http协议信息
- tomcat的安装
- java compiler level does not match the version of the installed java project facet
- 设计模式 - 结构型模式 - 外观模式
- Oracle expdp/impdp导出导入命令及数据库备份(转)