SqlMessage
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.State
{
/**//// <summary>
/// Sql方式操作Message
/// </summary>
public class SqlMessage : AbstractMessageState
{
/**//// <summary>
/// 構造函數
/// </summary>
/// <param name="message">Context類型參數</param>
public SqlMessage(Message message)
{
this._message = message;
}
/**//// <summary>
/// 改變狀態
/// </summary>
public override void StateChangeCheck()
{
}
/**//// <summary>
/// 獲取Message
/// </summary>
/// <returns></returns>
public override List<MessageModel> Get()
{
List<MessageModel> l = new List<MessageModel>();
l.Add(new MessageModel("SQL方式獲取Message", DateTime.Now));
return l;
}
/**//// <summary>
/// 插入Message
/// </summary>
/// <param name="mm">Message實體對象</param>
/// <returns></returns>
public override bool Insert(MessageModel mm)
{
// 代碼略
return true;
}
}
}
Message
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.State
{
/**//// <summary>
/// Context類
/// </summary>
public class Message
{
/**//// <summary>
/// 類型為狀態模式抽象類的私有變量
/// </summary>
private AbstractMessageState _abstractMessageState;
/**//// <summary>
/// 類型為狀態模式抽象類的屬性
/// </summary>
public AbstractMessageState AbstractMessageState
{
get { return _abstractMessageState; }
set { _abstractMessageState = value; }
}
/**//// <summary>
/// UserId私有變量
/// </summary>
private string _userId;
/**//// <summary>
/// UserId
/// </summary>
public string UserId
{
get { return _userId; }
set { _userId = value; }
}
/**//// <summary>
/// 構造函數
/// </summary>
/// <param name="userId">UserId</param>
public Message(string userId)
{
this._userId = userId;
_abstractMessageState = new XMLMessage(this);
}
/**//// <summary>
/// 獲取Message
/// </summary>
/// <returns></returns>
public List<MessageModel> Get()
{
// 修改狀態
_abstractMessageState.StateChangeCheck();
return _abstractMessageState.Get();
}
/**//// <summary>
/// 插入Message
/// </summary>
/// <param name="mm">Message實體對象</param>
/// <returns></returns>
public bool Insert(MessageModel mm)
{
// 修改狀態
_abstractMessageState.StateChangeCheck();
return _abstractMessageState.Insert(mm);
}
}
}