Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // 孙悟空 原型
            MonkeyKingPrototype prototypeMonkeyKing = new ConcretePrototype("MonkeyKing");

            // 变一个
            MonkeyKingPrototype cloneMonkeyKing = prototypeMonkeyKing.Clone() as ConcretePrototype;

            Console.WriteLine("Cloned1:\t" + cloneMonkeyKing.Id);

            // 变两个
            MonkeyKingPrototype cloneMonkeyKing2 = prototypeMonkeyKing.Clone() as ConcretePrototype;

            Console.WriteLine("Cloned2:\t" + cloneMonkeyKing2.Id);
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        /// 火影忍者中鸣人的影分身和孙悟空的的变都是原型模式
        private static void Main(string[] args)
        {
            // 孙悟空 原型
            MonkeyKingPrototype prototypeMonkeyKing = new ConcretePrototype(1);
            // 变一个
            MonkeyKingPrototype cloneMonkeyKing = prototypeMonkeyKing.Clone() as ConcretePrototype;

            if (cloneMonkeyKing != null)
            {
                Console.WriteLine("Cloned1:" + cloneMonkeyKing.Id);
            }
            // 变两个
            MonkeyKingPrototype cloneMonkeyKing2 = prototypeMonkeyKing.Clone() as ConcretePrototype;

            if (cloneMonkeyKing2 != null)
            {
                cloneMonkeyKing2.Id += 1;
                Console.WriteLine("Cloned2:" + cloneMonkeyKing2.Id);
            }

            Console.ReadLine();
        }