MessageModelComposite
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Composite
{
/**//// <summary>
/// Message實體樹枝(Composite)
/// </summary>
public class MessageModelComposite : MessageModelComponent
{
private List<MessageModelComponent> _list;
/**//// <summary>
/// 構造函數
/// </summary>
/// <param name="name">名稱</param>
public MessageModelComposite(string name)
: base(name)
{
_list = new List<MessageModelComponent>();
}
/**//// <summary>
/// 添加
/// </summary>
/// <param name="mmc">MessageModelComponent</param>
public override void Add(MessageModelComponent mmc)
{
_list.Add(mmc);
}
/**//// <summary>
/// 刪除
/// </summary>
/// <param name="mmc">MessageModelComponent</param>
public override void Remove(MessageModelComponent mmc)
{
_list.Remove(mmc);
}
/**//// <summary>
/// 獲取
/// </summary>
/// <param name="indent">縮進數</param>
/// <returns></returns>
public override string GetData(int indent)
{
string s = new String('—', indent) +
"樹枝名稱:" + _name +
"<br />";
foreach (MessageModelComponent mmc in _list)
{
s += mmc.GetData(indent + 2);
}
return s;
}
}
}