//private readonly BasicCar nano, ford; //public CarFactory() //{ // //nano = new Nano("Green Nano"); // //ford = new Ford("Ford Yellow"); //} public BasicCar GetNano() { //return nano.Clone(); if (nano != null) { // Nano was created earlier. // Returning a clone of it. return(nano.Clone()); } else { /* * Create a nano for the first * time and return it. */ nano = new Nano("Green Nano"); return(nano); } }
static void Main(string[] args) { Console.WriteLine("***Prototype Pattern Demo2.***\n"); 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 Rs. {basicCar.onRoadPrice}"); //Get a Ford now basicCar = carFactory.GetFord(); //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(); }