架构师训练营 - 作业 - 第三周
请在草稿纸上手写一个单例模式的实现代码
请用【组合设计模式】编写程序,打印输出图1的窗口,窗口组件的树结构如图2所示。打印输出示例参考图3。
组合模式
定义
又叫部分-整体模式,是用于把一组相似的对象当作一个单一的对象。组合模式依据树形结构来组合对象,用来表示部分及整体层次。这种类型的设计模式属于结构性模式,它创建了对象组的树形结构。实现组合模式使得客户端对单个对象和组合对象的使用具有一致性。
Wikipedia Definition
The composite pattern describes a group of objects that are treated as the same way as a single instance of the same type of the object. The intent of a composite is to "compose" objects into tree structures to represent part-whole hierarchies. Implementing the composite pattern lets clients treat individual objects and compositions uniformly.
UML Class Diagram
示例代码
Interface - Component
Implementation - Control(Picture/Button/Label/TextBox/PasswordBox/CheckBox/LinkLabel)
Implementation - Container(WinForm/Frame)
Reference
https://en.wikipedia.org/wiki/Composite_pattern
评论