Esempio n. 1
0
        static void Main(string[] args)
        {
            Supermarket Market = new Supermarket();

            Market.ShowRepository();
            Market.AskBuy();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Supermarket supermarket = new Supermarket();

            supermarket.AddProduct("Milk", new Milk(1m, "Something from a cow."));
            supermarket.AddProduct("Bread", new Bread(1.10m, "Combination of wheat and water."));

            /*
             * // This is what happens in the code below this commentblock.
             * //  Normal Clone/Copy.
             *
             * var clone = supermarket.GetProduct("Bread").Clone();
             * clone.Description.Data = "This description is changed! (Bread)";
             *
             *
             *
             * // Deep Copy
             *
             * var cloneDeep = supermarket.GetProduct("Milk").DeepCopy();
             * cloneDeep.Description.Data = "This description is changed! (Milk)";
             *
             */
            var clone = supermarket.GetProduct("Bread").Clone();

            Console.WriteLine("\n\n-------------------------------- Normal Copy: --------------------------------");
            Console.WriteLine("\n\n Before: \n -----------------");
            Console.WriteLine(" Clone: " + clone);
            Console.WriteLine(" Prototype: " + supermarket.GetProduct("Bread"));


            Console.WriteLine("\n [ Changing the description of the clone! ]");
            clone.Description.Data = "This description is changed! (Bread)";


            Console.WriteLine("\n\n After: \n -----------------");
            Console.WriteLine(" Clone: " + clone + "             <-- Changed!");
            Console.WriteLine(" Prototype:" + supermarket.GetProduct("Bread") + "          <-- Changed!");


            var cloneDeep = supermarket.GetProduct("Milk").DeepCopy();

            Console.WriteLine("\n\n-------------------------------- Deep Copy: --------------------------------");
            Console.WriteLine("\n\n Before: \n -----------------");
            Console.WriteLine(" Clone: " + cloneDeep);
            Console.WriteLine(" Prototype: " + supermarket.GetProduct("Milk"));


            Console.WriteLine("\n [ Changing the description of the clone! ]");
            cloneDeep.Description.Data = "This description is changed! (Milk)";


            Console.WriteLine("\n\n After: \n -----------------");
            Console.WriteLine(" Clone: " + clone + "             <-- Changed!");
            Console.WriteLine(" Prototype: " + supermarket.GetProduct("Milk") + "                       <-- Not Changed!");

            // Exit on keypress.
            Console.ReadKey();
        }