⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prototype.cs

📁 C#设计模式源码
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;

namespace DesignDll
{
    /**************************************************************************
     * 原型模型:用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象
     * ***********************************************************************/

    //优点 一般在初始化信息不发生变化的情况下,克隆是最好的办法。这样既隐藏了创建细节,又对性能是大大的提高
    /// <summary>
    /// 简历类
    /// </summary>
    /// 
    public class Resume :ICloneable
    {
        //姓名
        public string Name;
        //年龄
        public string Age;
        //工作年龄
        public string WorkYear;
        //性别
        public string Sex;
        //公司
        public string Company;

        //
        public List<string> stringlist = new List<string>();
        /// <summary>
        /// 构造函数,且有姓名
        /// </summary>
        /// <param name="name"></param>
        public Resume(string name)
        {
            this.Name = name;
        }

        public Resume(string ss ,int i )
        {
            //this.stringlist = templist;
        }


        /// <summary>
        /// 设置个人信息
        /// </summary>
        /// <param name="age">年龄</param>
        /// <param name="sex">性别</param>
        public void SetPersonInformation(string age, string sex)
        {
            this.Sex = sex;
            this.Age = age;
        }

        /// <summary>
        /// 设置工作经验
        /// </summary>
        /// <param name="workyear">工作年龄</param>
        /// <param name="company">公司</param>
        public void SetWorkInformation(string workyear, string company)
        {
            this.Company = company;
            this.WorkYear = workyear;
        }

        /// <summary>
        /// 克隆对象(浅拷贝)
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            return (object)this.MemberwiseClone();
        }

        public object CloneDepth(string sDepth)
        {
            Resume obj = new Resume(sDepth,1);
            obj.Name = this.Name;
            obj.Sex = this.Sex;
            obj.Age = this.Age;
            obj.Company = this.Company;
            obj.stringlist = this.stringlist;
            obj.WorkYear = this.WorkYear;
            return obj;
        }

        public List<string> getList(string good)
        {
            stringlist.Add(good);
            return stringlist;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -