コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("***Prototype Pattern Demo***\n");
            BasicCar nano_base = new Nano("Green Nano");

            nano_base.price = 100000;
            BasicCar ford_basic = new Ford("Ford Yellow");

            ford_basic.price = 500000;

            BasicCar bc1;

            //Clone Nano Object
            bc1 = (BasicCar)nano_base.Clone();
            //Price will be more than 100000 for sure
            bc1.price = nano_base.price + BasicCar.setPrice();
            Console.WriteLine("Car is: " + bc1.modelname + " and it's price is Rs." + bc1.price);

            bc1 = (BasicCar)ford_basic.Clone();
            //Price will be more than 100000 for sure
            bc1.price = ford_basic.price + BasicCar.setPrice();
            Console.WriteLine("Car is: " + bc1.modelname + " and it's price is Rs." + bc1.price);

            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("***Prototype Pattern Demo***\n");
            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($"Cas is {bc1.ModelName}, and it's price is Rs. {bc1.Price}");
            // Ford
            bc1       = ford_base.Clone();
            bc1.Price = ford_base.Price + BasicCar.SetPrice();
            Console.WriteLine($"Cas is {bc1.ModelName}, and it's price is Rs. {bc1.Price}");
        }