XMLMessageBuilder
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Builder
{
/**//// <summary>
/// XMLMessage建造者(ConcreteBuilder)
/// </summary>
public class XMLMessageBuilder : AbstractMessageBuilder
{
/**//// <summary>
/// 構造函數
/// </summary>
public XMLMessageBuilder()
: base("XML")
{
}
/**//// <summary>
/// 建造XML插入方法
/// </summary>
/// <param name="mm">Message實體對象</param>
public override void BuilderInsert(MessageModel mm)
{
base._Operation["insert"] = "XMLMessage|Insert|"+mm.Message+"|"+mm.PublishTime.ToString()+"";
}
/**//// <summary>
/// 建造XML獲取方法
/// </summary>
public override void BuilderGet()
{
base._Operation["get"] = "XMLMessage|Get";
}
}
}
Message
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Builder
{
/**//// <summary>
/// 指導者(Director)
/// </summary>
public class Message
{
/**//// <summary>
/// 調用具體建造者角色以創建產品對象
/// </summary>
/// <param name="messageBuilder">AbstractMessageBuilder</param>
/// <param name="mm">Message實體對象</param>
public void Construct(AbstractMessageBuilder messageBuilder, MessageModel mm)
{
messageBuilder.BuilderInsert(mm);
messageBuilder.BuilderGet();
}
}
}