通过复制原型来创造新的对象。

 

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        public abstract class Prototype
        {
            private string id;

            public Prototype(string id)
            {
                this.id = id;
            }


            public string Id
            {
                get { return id; }
                set { id = value; }
            }

            public abstract Prototype Clone();
        }

        public class ConcretePrototypeA: Prototype
        {
            public ConcretePrototypeA(string id) : base(id)
            {
            }

            public override Prototype Clone()
            {
                return (Prototype) this.MemberwiseClone();
            }
        }

        static void Main(string[] args)
        {
            ConcretePrototypeA pa = new ConcretePrototypeA("a");
            ConcretePrototypeA pac1 = (ConcretePrototypeA)pa.Clone();
            ConcretePrototypeA pac2 = (ConcretePrototypeA)pa.Clone();

            Console.WriteLine(pac1.Id);
            Console.WriteLine(pac2.Id);
        }
    }
}