AbstractMessage
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Flyweight
{
/**//// <summary>
/// 操作Message抽象類(Flyweight)
/// </summary>
public abstract class AbstractMessage
{
/**//// <summary>
/// 獲取Message
/// </summary>
/// <returns></returns>
public abstract List<MessageModel> Get();
/**//// <summary>
/// 插入Message
/// </summary>
/// <param name="mm">Message實體對象</param>
/// <returns></returns>
public abstract bool Insert(MessageModel mm);
}
}
SqlMessage
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Flyweight
{
/**//// <summary>
/// Sql方式操作Message(ConcreteFlyweight)
/// </summary>
public class SqlMessage : AbstractMessage
{
/**//// <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;
}
}
}