Inheritance: Prototype.AbstractPrototype
Beispiel #1
0
        static void Main(string[] args)
        {
            Prototype prototype = null;
            Prototype clone = null;

            prototype = new ConcretePrototype1(1);
            clone = prototype.Clone();

            prototype = new ConcretePrototype2(2);
            clone = prototype.Clone();
        }
Beispiel #2
0
    static void Main()
    {
      // Create two instances and clone each 
      Prototype prototype1 = new ConcretePrototype1("I");
      Prototype clonedPrototype1 = prototype1.Clone();
      Console.WriteLine ("Cloned: {0}", clonedPrototype1 .Id);
 
      Prototype prototype2 = new ConcretePrototype2("II");
      Prototype clonedPrototype2 = prototype2.Clone();
      Console.WriteLine ("Cloned: {0}", clonedPrototype2 .Id);
    }
Beispiel #3
0
        static void Main(string[] args)
        {
            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();
            Console.WriteLine("Cloned: {0}", c1.Id);

            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();
            Console.WriteLine("Cloned: {0}", c2.Id);
            
            Console.ReadKey();
        }
Beispiel #4
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // Create two instances and clone each
            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();
            Console.WriteLine("Cloned: {0}", c1.Id);

            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();
            Console.WriteLine("Cloned: {0}", c2.Id);

            // Wait for user
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned {0}", c1.Id);


            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned {0}", c2.Id);
            Console.Read();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            ConcretePrototype1 p1    = new ConcretePrototype1("1610207");
            ConcretePrototype1 copy1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", copy1.ID);

            ConcretePrototype2 p2    = new ConcretePrototype2("La Quoc Thang");
            ConcretePrototype2 copy2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned: {0}", copy2.ID);

            Console.ReadKey();
        }
        static void Main()
        {
            // Создание двух экземпляров и клонирование их.
            ConcretePrototype1 p1 = new ConcretePrototype1("1");
            ConcretePrototype1 c1 = p1.Clone() as ConcretePrototype1;

            Console.WriteLine("Cloned: {0}", c1.Id);

            ConcretePrototype2 p2 = new ConcretePrototype2("2");
            ConcretePrototype2 c2 = p2.Clone() as ConcretePrototype2;

            Console.WriteLine("Cloned: {0}", c2.Id);

            // Задержка.
            Console.ReadKey();
        }
Beispiel #8
0
        static void Main()
        {
            // Create two instances and clone each
            var p1 = new ConcretePrototype1("I");
            var c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", c1.Id);

            var p2 = new ConcretePrototype2("II");
            var c2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned: {0}", c2.Id);

            // Wait for user
            Console.Read();
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            ConcretePrototype1 p1       = new ConcretePrototype1("p1");
            ConcretePrototype1 clonedP1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine(clonedP1.Id);
            Console.WriteLine(p1.Equals(clonedP1));

            ConcretePrototype2 p2       = new ConcretePrototype2("p2");
            ConcretePrototype2 clonedP2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine(clonedP2.Id);
            Console.WriteLine(p2.Equals(clonedP2));

            Console.Read();
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            // Create two instances and clone each

            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", c1.Id);

            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned: {0}", c2.Id);

            // Wait for user
            Console.ReadKey();
        }
Beispiel #11
0
        public static void Run()
        {
            Console.WriteLine("This structural code demonstrates the Prototype pattern in which new objects are created by copying pre-existing objects (prototypes) of the same class.");
            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", c1.Id);
            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned: {0}", c2.Id);

            /*
             * Cloned: I
             * Cloned: II
             */
        }
        static void Main1(string[] args)
        {
            // Create two instances and clone each

            ConcretePrototype1 p1 = new ConcretePrototype1("I");

            Console.WriteLine("Cloned: {0}", p1.Id);
            ConcretePrototype1 client1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", client1.Id);

            ConcretePrototype2 p2      = new ConcretePrototype2("II");
            Prototype          client2 = p2.Clone();

            Console.WriteLine("Cloned: {0}", client2.Id);

            Console.ReadKey();
        }
Beispiel #13
0
        static void Main()
        {
            // Create two instances and clone each

            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();

            MessageBox.Show("Cloned: " + c1.Id);

            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();

            MessageBox.Show("Cloned: " + c2.Id);

            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            var prototype = new ConcretePrototype1
            {
                Property1        = "A",
                Property2        = "B",
                PrototypeDetails = new PrototypeDetails {
                    Details = "prototype details"
                }
            };

            var NewObject = prototype.Clone() as ConcretePrototype1;

            NewObject.PrototypeDetails.Details = "New details for 'NewObject'";

            Console.WriteLine(prototype);
            Console.WriteLine(NewObject);


            var prototype2 = new ConcretePrototype2
            {
                Property1        = "X",
                Property2        = "Y",
                OtherProperty    = "Z",
                PrototypeDetails = new PrototypeDetails {
                    Details = "prototype2 details"
                }
            };

            var NewObject2 = prototype2.Clone() as ConcretePrototype2;

            NewObject2.PrototypeDetails.Details = "New details for 'NewObject2'";

            Console.WriteLine(prototype2);
            Console.WriteLine(NewObject2);

            Console.ReadKey();
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            #region 结构实现
            // Create two instances and clone each
            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();
            Console.WriteLine("Cloned: {0}", c1.Id);

            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();
            Console.WriteLine("Cloned: {0}", c2.Id);
            #endregion

            Console.WriteLine("******************************");

            #region 实践应用
            ColorManager colormanager = new ColorManager();

            // Initialize with standard colors
            colormanager["red"]   = new Color(255, 0, 0);
            colormanager["green"] = new Color(0, 255, 0);
            colormanager["blue"]  = new Color(0, 0, 255);

            // User adds personalized colors
            colormanager["angry"] = new Color(255, 54, 0);
            colormanager["peace"] = new Color(128, 211, 128);
            colormanager["flame"] = new Color(211, 34, 20);

            // User clones selected colors
            Color color1 = colormanager["red"].Clone() as Color;
            Color color2 = colormanager["peace"].Clone() as Color;
            Color color3 = colormanager["flame"].Clone() as Color;
            #endregion

            Console.ReadKey();
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            ConcretePrototype1 p1 = new ConcretePrototype1("Prototype I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine($"Cloned c1\n{GetDetails(c1)}");
            Console.WriteLine($"From p1\n{GetDetails(p1)}");

            ConcretePrototype2 p2 = new ConcretePrototype2("Prototype II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine($"Cloned c2\n{GetDetails(c2)}");
            Console.WriteLine($"From p2\n{GetDetails(p2)}");

            // Output:
            // Cloned c1
            // ID: Prototype I  hashcode: 58225482
            // From p1
            // ID: Prototype I  hashcode: 54267293
            // Cloned c2
            // ID: Prototype II  hashcode: 18643596
            // From p2
            // ID: Prototype II  hashcode: 33574638
        }