Beispiel #1
0
        static void Main(string[] args)
        {
            CarPrototype carBase = new Ford {
                Model = "Ford",
                Color = "White",
                Price = 500000
            };


            Ford fordXSeries = (Ford)carBase.Clone();

            fordXSeries.Model += "X Series";
            fordXSeries.Price += 50000;
            fordXSeries.Color  = "Metallic Blue";

            Ford fordZSeries = (Ford)carBase.Clone();

            fordZSeries.Model += "Z Series";
            fordZSeries.Price += 75000;
            fordZSeries.Color  = "Metallic Red";

            Console.WriteLine("Quotation: {0} is available in {1}, Price:{2}", fordXSeries.Model, fordXSeries.Color, fordXSeries.Price, Ford.Frame);
            Console.WriteLine("Quotation: {0} is available in {1}, Price:{2}", fordZSeries.Model, fordZSeries.Color, fordZSeries.Price, Ford.Frame);

            carBase.Price     += 5000;
            carBase.Color      = "White Chromium";
            CarPrototype.Frame = "Oval";
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("***Prototype Pattern Demo***\n");
            //Base or Original Copy
            BasicCar nano = new Nano("Green Nano");
            BasicCar ford = new Ford("Ford Yellow");

            //Console.WriteLine("Before clone, base prices:");
            //Console.WriteLine($"Car is: {nano.ModelName}, and it's base price is Rs. {nano.basePrice}");
            //Console.WriteLine($"Car is: {ford.ModelName}, and it's base price is Rs. {ford.basePrice}");

            BasicCar basicCar;

            // Nano
            basicCar = nano.Clone();
            // Working on cloned copy
            basicCar.onRoadPrice = basicCar.basePrice + BasicCar.SetAdditionalPrice();
            Console.WriteLine($"Car is: {basicCar.ModelName}, and it's price is Rs. {basicCar.onRoadPrice}");

            // Ford
            basicCar = ford.Clone();
            // Working on cloned copy
            basicCar.onRoadPrice = basicCar.basePrice + BasicCar.SetAdditionalPrice();
            Console.WriteLine($"Car is: {basicCar.ModelName}, and it's price is Rs. {basicCar.onRoadPrice}");
            Console.ReadLine();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("***Prototype Pattern Demo***\n");

            //Base or Original Copy
            BasicCar nano_base = new Nano("Green Nano")
            {
                Price = 100000
            };
            BasicCar ford_base = new Ford("Ford Yellow")
            {
                Price = 500000
            };
            BasicCar bc1;

            //Nano
            bc1       = nano_base.Clone();
            bc1.Price = nano_base.Price + BasicCar.SetPrice();
            Console.WriteLine("Car is: {0}, and it's price is Rs. {1}", bc1.ModelName, bc1.Price);

            //Ford
            bc1       = ford_base.Clone();
            bc1.Price = ford_base.Price + BasicCar.SetPrice();
            Console.WriteLine("Car is: {0}, and it's price is Rs. {1}",
                              bc1.ModelName, bc1.Price);
            Console.ReadLine();
        }
Beispiel #4
0
        static void Main()
        {
            Console.WriteLine("***Prototype Pattern Demo***\n");
            BasicCar nanoBase = new Nano("Green Nano")
            {
                Price = 10000
            };
            BasicCar fordBase = new Ford("Ford Yellow")
            {
                Price = 5000
            };

            BasicCar bc1 = nanoBase.Clone();

            bc1.Price = nanoBase.Price + BasicCar.SetPrice();
            Console.WriteLine("Car is: {0}, and it's price is Rs. {1}", bc1.ModelName, bc1.Price);

            bc1       = fordBase.Clone();
            bc1.Price = fordBase.Price + BasicCar.SetPrice();
            Console.WriteLine("Car is: {0}, and it's price is Rs. {1}", bc1.ModelName, bc1.Price);

            Console.ReadLine();
        }