using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesignPattern
{
//原型模式
internal class PrototypePattern
{
private void main()
{
ConcretePrototype prototype = new ConcretePrototype();
ConcretePrototype copy = (ConcretePrototype)prototype.Clone();
}
}
abstract class Prototype
{
public abstract Prototype Clone();
}
class ConcretePrototype : Prototype
{
public string? Attr { get; set; }
private Member? member;
public override Prototype Clone()//浅克隆
{
ConcretePrototype clone = new ConcretePrototype();
clone.Attr = Attr;
return clone;
}
//浅克隆:只克隆值类型
//深克隆:克隆值类型和引用类型
public Prototype Clone2()//浅克隆
{
return (ConcretePrototype)this.MemberwiseClone();
}
public Prototype Clone3()//深克隆
{
ConcretePrototype clone = new ConcretePrototype();
Member _member = new Member();
clone.member = _member;
clone.Attr = Attr;
return clone;
}
}
class Member { }
}