C# 中的原型模式示例

原型模式,把对象从内存层面复制,然后返回。
不经过类的构造函数,但是是一个全新的对象。

    public class Prototype
    {
    
    
        private Prototype()
        {
    
    
            Console.WriteLine("构造.");
        }

        private static readonly Prototype prototype = new Prototype();

        public static Prototype CreateInstance()
        {
    
    
        	// MemberwiseClone 创建当前 Object 的浅表副本。
            return prototype.MemberwiseClone() as Prototype;
        }
    }

猜你喜欢

转载自blog.csdn.net/Upgrader/article/details/107498497