コード例 #1
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();
        }
コード例 #2
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();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: marcel1992/DesignPatterns
        static void Main(string[] args)
        {
            Console.WriteLine("Prototype pattern");
            CarFactory carFactory = new CarFactory();
            //get a Nano
            BasicCar basicCar = carFactory.GetNano();

            //working on cloned copy
            basicCar.OnRoadPrice = basicCar.BasePrice + BasicCar.SetAdditionalPrice();
            Console.WriteLine($"Car is: {basicCar.ModelName}, and it's price is {basicCar.OnRoadPrice}");

            //get a Ford
            basicCar = carFactory.GetFord();
            //working on cloned copy
            basicCar.OnRoadPrice = basicCar.BasePrice + BasicCar.SetAdditionalPrice();
            Console.WriteLine($"Car is: {basicCar.ModelName}, and it's price is {basicCar.OnRoadPrice}");

            Console.ReadLine();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("----- Prototype Pattern Implementation -----");
            Console.WriteLine("Prototype: BasicCat /t Concrete classes: Mercedes, Toyota");
            Console.WriteLine("");

            //Original Copies
            BasicCar MercedesOriginal = new Mercedes("MERCEDES")
            {
                Price = 49500
            };
            BasicCar ToyotaOriginal = new Toyota("TOYOTA")
            {
                Price = 27800
            };

            //Show values of Originals
            Console.WriteLine($"MERCEDES\n Model: {MercedesOriginal.ModelName}\n PRICE: {MercedesOriginal.Price}");
            Console.WriteLine($"TOYOTA\n Model: {ToyotaOriginal.ModelName}\n PRICE: {ToyotaOriginal.Price}");

            Console.WriteLine("");
            //Copies
            BasicCar MercedesCopy = MercedesOriginal.Clone();

            MercedesCopy.Price = MercedesCopy.Price + 1211; // Ex: Modify a field
            BasicCar ToyotaCopy = ToyotaOriginal.Clone();

            ToyotaCopy.Price = ToyotaCopy.Price + 851; // Ex: Modify a field

            //Show values of Copies
            Console.WriteLine($"MERCEDES\n Model: {MercedesCopy.ModelName}\n PRICE: {MercedesCopy.Price}");
            Console.WriteLine($"TOYOTA\n Model: {ToyotaCopy.ModelName}\n PRICE: {ToyotaCopy.Price}");

            if (MercedesOriginal != MercedesCopy && ToyotaOriginal != ToyotaCopy)
            {
                Console.WriteLine("\n Prototype Design Pattern implemented successfully!\n");
            }

            Console.Read();
        }
コード例 #5
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();
        }