创建型模式之原型模式

概述

在使用原型模式时,我们需要首先创建一个原型对象,再通过复制这个原型对象来创建更多同类型的对象

定义

原型模式(Prototype  Pattern):使用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象。原型模式是一种对象创建型模式。

实现

    public class Resume : ICloneable
    {
        public string name { get; set; }
        public bool sex { get; set; }
        public string IdentityCardNo { get; set; }
        public DateTime birthday { get; set; }
        public double workYear { get; set; }
        /**     简历中的其他信息省略    */


        public void Show()
        {
            Console.WriteLine("这是{0}的简历", name);
        }
        /// <summary>
        /// 浅克隆
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }

 

原文地址:https://www.cnblogs.com/Jabben_Yi/p/5538654.html