AbstractMessageBuilder
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Builder
{
/**//// <summary>
/// 抽象Message建造者(Builder)
/// </summary>
public abstract class AbstractMessageBuilder
{
/**//// <summary>
/// 構造函數
/// </summary>
/// <param name="type">產品類型</param>
public AbstractMessageBuilder(string type)
{
this._operation = new Operation(type);
}
/**//// <summary>
/// 操作(Product)
/// </summary>
protected Operation _Operation;
/**//// <summary>
/// 操作(Product)
/// </summary>
public Operation Operation
{
get { return _Operation; }
set { _Operation = value; }
}
/**//// <summary>
/// 建造插入方法
/// </summary>
/// <param name="mm"></param>
abstract public void BuilderInsert(MessageModel mm);
/**//// <summary>
/// 建造獲取方法
/// </summary>
abstract public void BuilderGet();
}
}
SqlMessageBuilder
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Builder
{
/**//// <summary>
/// SqlMessage建造者(ConcreteBuilder)
/// </summary>
public class SqlMessageBuilder : AbstractMessageBuilder
{
/**//// <summary>
/// 構造函數
/// </summary>
public SqlMessageBuilder()
: base("sql")
{
}
/**//// <summary>
/// 建造Sql插入方法
/// </summary>
/// <param name="mm">Message實體對象</param>
public override void BuilderInsert(MessageModel mm)
{
base._Operation["insert"] = "SqlMessage|Insert|" + mm.Message + "|" + mm.PublishTime.ToString() + "";
}
/**//// <summary>
/// 建造Sql獲取方法
/// </summary>
public override void BuilderGet()
{
base._Operation["get"] = "SqlMessage|Get";
}
}
}