static void Main(string[] args) { ICar toyota = new Honda(); Console.WriteLine(toyota.CarMake()); Console.WriteLine(toyota.Drive()); }
// Builds requested vehicle if we haven't already public void BuildVehicle(string make) { ICar car = null; // If we already have that vehicle don't create another if (cars.ContainsKey(make)) { Console.WriteLine("You can only have one of each type of car."); return; } // Create all new vehicles if (make.Equals("Honda", StringComparison.OrdinalIgnoreCase)) { car = new Honda(make); cars.Add(make, car); return; } if (make.Equals("Toyota", StringComparison.OrdinalIgnoreCase)) { car = new Toyota(make); cars.Add(make, car); return; } if (make.Equals("Subaru", StringComparison.OrdinalIgnoreCase)) { car = new Subaru(make); cars.Add(make, car); return; } // If this factory doesn't make the requested vehicle let the user know Console.WriteLine($"This factory does not make {make} vehicles."); return; }