AbstractMessageWrapper
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Decorator
{
/**//// <summary>
/// 裝飾AbstractMessage(Decorator)
/// </summary>
public abstract class AbstractMessageWrapper : AbstractMessage
{
private AbstractMessage _abstractMessage;
/**//// <summary>
/// 構造函數
/// </summary>
/// <param name="abstractMessage">AbstractMessage</param>
public AbstractMessageWrapper(AbstractMessage abstractMessage)
{
this._abstractMessage = abstractMessage;
}
/**//// <summary>
/// 獲取Message
/// </summary>
/// <returns></returns>
public override List<MessageModel> Get()
{
return _abstractMessage.Get();
}
/**//// <summary>
/// 插入Message
/// </summary>
/// <param name="mm">Message實體對象</param>
/// <returns></returns>
public override bool Insert(MessageModel mm)
{
return _abstractMessage.Insert(mm);
}
}
}
CheckUserWrapper
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Decorator
{
/**//// <summary>
/// 擴展出用戶驗證的功能(ConcreteDecorator)
/// </summary>
public class CheckUserWrapper : AbstractMessageWrapper
{
/**//// <summary>
/// 構造函數
/// </summary>
/// <param name="abstractMessage">AbstractMessage</param>
public CheckUserWrapper(AbstractMessage abstractMessage)
: base(abstractMessage)
{
}
/**//// <summary>
/// 獲取Message
/// </summary>
/// <returns></returns>
public override List<MessageModel> Get()
{
List<MessageModel> l = base.Get();
foreach (MessageModel mm in l)
{
mm.Message += "(經過用戶驗證)";
}
return l;
}
/**//// <summary>
/// 插入Message
/// </summary>
/// <param name="mm">Message實體對象</param>
/// <returns></returns>
public override bool Insert(MessageModel mm)
{
// 在這裡擴展功能
return base.Insert(mm);
}
}
}