XMLMessage
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Strategy
{
/**//// <summary>
/// XML方式操作Message
/// </summary>
public class XMLMessage : IMessageStrategy
{
/**//// <summary>
/// 獲取Message
/// </summary>
/// <returns></returns>
public List<MessageModel> Get()
{
List<MessageModel> l = new List<MessageModel>();
l.Add(new MessageModel("XML方式獲取Message", DateTime.Now));
return l;
}
/**//// <summary>
/// 插入Message
/// </summary>
/// <param name="mm">Message實體對象</param>
/// <returns></returns>
public bool Insert(MessageModel mm)
{
// 代碼略
return true;
}
}
}
Message
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Strategy
{
/**//// <summary>
/// Context類
/// </summary>
public class Message
{
/**//// <summary>
/// 聲明一個IMessageStrategy類型
/// </summary>
private IMessageStrategy _strategy;
/**//// <summary>
/// 構造函數
/// </summary>
/// <param name="strategy">具體算法</param>
public Message(IMessageStrategy strategy)
{
this._strategy = strategy;
}
/**//// <summary>
/// 獲取Message
/// </summary>
/// <returns></returns>
public List<MessageModel> Get()
{
return _strategy.Get();
}
/**//// <summary>
/// 插入Message
/// </summary>
/// <param name="mm">Message實體對象</param>
/// <returns></returns>
public bool Insert(MessageModel mm)
{
return _strategy.Insert(mm);
}
}
}