[索引页]
[源码下载]


乐在其中设计模式(C#) - 组合模式(Composite Pattern)


作者:webabcd


介绍
将对象组合成树形结构以表示“部分-整体”的层次结构。它使得客户对单个对象和复合对象的使用具有一致性。


示例
有一个Message实体类,使其单个对象和复合对象具有一致性。
乐在其中设计模式(C#) - 组合模式(Composite Pattern)


MessageModel
乐在其中设计模式(C#) - 组合模式(Composite Pattern)using System;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Text;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
namespace Pattern.Composite

MessageModelComponent
乐在其中设计模式(C#) - 组合模式(Composite Pattern)using System;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Text;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
namespace Pattern.Composite

MessageModelLeaf
乐在其中设计模式(C#) - 组合模式(Composite Pattern)using System;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Text;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
namespace Pattern.Composite

MessageModelComposite
乐在其中设计模式(C#) - 组合模式(Composite Pattern)using System;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Text;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
namespace Pattern.Composite


Test
乐在其中设计模式(C#) - 组合模式(Composite Pattern)using System;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Data;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Configuration;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Collections;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Web;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Web.Security;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Web.UI;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Web.UI.WebControls;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Web.UI.WebControls.WebParts;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using System.Web.UI.HtmlControls;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
using Pattern.Composite;
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
乐在其中设计模式(C#) - 组合模式(Composite Pattern)
public partial class Composite : System.Web.UI.Page

运行结果
—树枝名称:树枝A
———树叶名称:树叶A;信息内容:Message内容A
———树叶名称:树叶B;信息内容:Message内容B
———树枝名称:树枝B
—————树叶名称:树叶C;信息内容:Message内容C
—————树叶名称:树叶D;信息内容:Message内容D
———树叶名称:树叶E;信息内容:Message内容E


参考
http://www.dofactory.com/Patterns/PatternComposite.aspx


OK
[源码下载]

相关文章: