【设计模式】之 Composite 合成模式
来源:互联网 发布:手机上可以开淘宝店吗 编辑:程序博客网 时间:2024/04/30 01:42
.
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Collections;namespace DesignFactory{ /// <summary> /// 合成模式 /// 基本图像元素 直线 圆 /// 复合图像 图形树 /// </summary> class CompositePattern { } abstract class DrawingElement { protected string name; public DrawingElement(string name) { this.name = name; } abstract public void Display(int indent); } class PrimitiveElement : DrawingElement { public PrimitiveElement(string name) : base(name) { } public override void Display(int indent) { Console.WriteLine(new String('-',indent) + "draw a {0}",name); } } class CompositeElement : DrawingElement { private ArrayList elements = new ArrayList(); public CompositeElement(string name) : base(name) { } public void Add(DrawingElement d) { elements.Add(d); } public void Remove(DrawingElement d) { elements.Remove(d); } public override void Display(int indent) { Console.WriteLine(new String('-', indent) + "+", name); foreach (DrawingElement c in elements) { c.Display(indent + 2); } } } public class CompositeApp { public static void Main(string[] args) { CompositeElement root = new CompositeElement("Picture"); root.Add(new PrimitiveElement("Red Line")); root.Add(new PrimitiveElement("Blue Circle")); root.Add(new PrimitiveElement("Green Box")); CompositeElement comp = new CompositeElement("Two Circles"); comp.Add(new PrimitiveElement("Black Circle")); comp.Add(new PrimitiveElement("White Circle")); root.Add(comp); PrimitiveElement P = new PrimitiveElement("Yellow Line"); root.Add(P); root.Remove(P); root.Display(1); } }}
- 【设计模式】之 Composite 合成模式
- java设计模式之Composite(合成)
- 恋爱中的设计模式 之 Composite模式 (合成模式)
- Java设计模式之合成模式(Composite)
- C# 设计模式--合成模式(Composite)
- 设计模式——合成模式(Composite)
- 设计模式学习笔记--合成(Composite)模式
- 合成模式(Composite) -- (模式之六)
- 设计模式之Composite
- 设计模式之Composite
- 设计模式之Composite
- 设计模式之 composite
- 合成(Composite)模式
- 合成模式(Composite Pattern)
- 合成(Composite)模式
- 合成模式(Composite Pattern)
- 合成(Composite)模式
- 合成模式(Composite Pattern)
- 【设计模式】之 Prototype 原型模式
- 静态方法vs非静态方法
- 【设计模式】之 Adapter 适配器模式
- PlayBook NDK编程如何获取系统时间
- 在Ubuntu上为Android系统的Application Frameworks层增加硬件访问服务
- 【设计模式】之 Composite 合成模式
- 在Ubuntu为Android硬件抽象层(HAL)模块编写JNI方法提供Java访问硬件服务接口
- 【设计模式】之 Decorator 装饰模式
- 转载:oracle定时任务
- SPI
- 联动显示隐藏+部分验证实例
- 只允许遍历链表一遍,定位链表倒数第m个元素
- as3 代码分享 第一章 图片缩放
- jvm与tomcat内存设置