C#设计模式02——原型模式的写法
public class ProteType { private static ProteType _ProteType = new ProteType(); private ProteType() { } public static ProteType GetInstance() { return (ProteType)_ProteType.MemberwiseClone(); } }
运行测试
var a1 = ProteType.GetInstance(); var a2 = ProteType.GetInstance(); Console.WriteLine($"a1 和 a2 是同一实例:{ object.ReferenceEquals(a1, a2)}");
源码下载:https://gitee.com/weilong2020/csharp_23_-design-patterns.git
付费内容,请联系本人QQ:1002453261
本文来自博客园,作者:明志德道,转载请注明原文链接:https://www.cnblogs.com/for-easy-fast/p/14374083.html