zoukankan      html  css  js  c++  java
  • 设计模式 原型模式(浅拷贝)

    先写简历

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Prototype
    {
        class Resume:ICloneable
        {
            private string name;
            private string sex;
            private string age;
            private string timeArea;
            private string company;
    
            public Resume(string name)
            {
                this.name = name;
            }
    
            public void SetPersonalInfo(string sex,string age)
            {
                this.sex = sex;
                this.age = age;
            }
    
            public void SetWorkExperience(string timeArea,string company)
            {
                this.timeArea = timeArea;
                this.company = company;
            }
    
            public void Display()
            {
                Console.WriteLine("{0} {1} {2}", name, sex, age);
                Console.WriteLine("工作经历:{0} {1}", timeArea, company);
            }
    
            public Object Clone()
            {
                return (Object)this.MemberwiseClone();
            }
        }
    }
    

    在写测试函数

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Prototype
    {
        class Program
        {
            static void Main(string[] args)
            {
                Resume a = new Resume("大鸟");
                a.SetPersonalInfo("男", "29");
                a.SetWorkExperience("1990-2000", "xx公司");
    
                Resume b = (Resume)a.Clone();
                b.SetWorkExperience("1998-2006", "yy企业");
    
                Resume c = (Resume)a.Clone();
                c.SetPersonalInfo("男", "24");
    
                a.Display();
                b.Display();
                c.Display();
    
                Console.Read();
            }
        }
    }
    
    
    
  • 相关阅读:
    python中用exit退出程序
    习题5-2 使用函数求奇数和 (15分)
    习题5-1 符号函数 (10分)
    练习5-3 数字金字塔 (15分)
    练习5-2 找两个数中最大者 (10分)
    练习5-1 求m到n之和 (10分)
    ubuntu使用教程
    图解HTTP 上
    Sublime Text 3 插件
    两千行PHP学习笔记
  • 原文地址:https://www.cnblogs.com/yufenghou/p/6024352.html
Copyright © 2011-2022 走看看