ShallowCopy
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Prototype
{
/**//// <summary>
/// 淺拷貝
/// </summary>
public class ShallowCopy : ICloneable
{
/**//// <summary>
/// 構造函數
/// </summary>
public ShallowCopy()
{
}
/**//// <summary>
/// 實現ICloneable的Clone()方法
/// </summary>
/// <returns></returns>
public Object Clone()
{
return this.MemberwiseClone();
}
private MessageModel _mm;
/**//// <summary>
/// Message實體對象
/// </summary>
public MessageModel MessageModel
{
get { return _mm; }
set { _mm = value; }
}
}
}
DeepCopy
using System;
using System.Collections.Generic;
using System.Text;
namespace Pattern.Prototype
{
/**//// <summary>
/// 深拷貝
/// </summary>
public class DeepCopy : ICloneable
{
/**//// <summary>
/// 構造函數
/// </summary>
public DeepCopy()
{
}
/**//// <summary>
/// 構造函數
/// </summary>
/// <param name="mm">Message實體對象</param>
public DeepCopy(MessageModel mm)
{
_mm = mm;
}
/**//// <summary>
/// 實現ICloneable的Clone()方法
/// </summary>
/// <returns></returns>
public Object Clone()
{
return new DeepCopy(new MessageModel(_mm.Message, _mm.PublishTime));
}
private MessageModel _mm;
/**//// <summary>
/// Message實體對象
/// </summary>
public MessageModel MessageModel
{
get { return _mm; }
set { _mm = value; }
}
}
}