/// <summary> /// The Client /// </summary> static void Main(string[] args) { var superBuilder = new SuperCarBuilder(); var notSuperBuilder = new NotSoSuperCarBuilder(); var factory = new Carfactory(); var builders = new List <CarBuilder> { superBuilder, notSuperBuilder }; foreach (var b in builders) { var c = factory.Build(b); Console.WriteLine($"The car requested by " + $"{b.GetType().Name}: " + $"\n-----------------------------------" + $"\nDoors: {c.Doors}" + $"\nSeats: {c.Seats}" + $"\nHorse power: {c.HorsePower}" + $"\nImpressive feature: {c.MostImpressiveFeature}" + $"\nTop speed: {c.TopSpeedMPH} mph\n"); } }
/// <summary> /// The Client /// </summary> static void Main(string[] args) { //all other classes were written by the prof ahead of time //instantiate a couple builders: var superBuilder = new SuperCarBuilder(); var notSoSuperBuilder = new NotSoSuperCarBuilder(); //instantiate a car factory: var factory = new Carfactory(); //create a collection of the car builders: //(so we can later loop through them) var builders = new List <CarBuilder> { superBuilder, notSoSuperBuilder }; //for each builder //first assign "car" within this loop //to one builder at a time. //then get the specs for that car. foreach (var builder in builders) { var car = factory.Build(builder); Console.WriteLine($"The car requested by " + $"{builder.GetType().Name}: " + $"\nHorsepower: {car.HorsePower}" + $"\nImpressive feature: {car.MostImpressiveFeature}" + $"\nTop Speed: {car.TopSpeedMPH} mph.\n"); } }
static void Main(string[] args) { var superCarBuilder = new SuperCarBuilder(); var notSoSuperCarBuilderButOk = new NotSoSuperCarBuilderButOk(); var factory = new CarFactory(); var builders = new List <CarBuilder> { superCarBuilder, notSoSuperCarBuilderButOk }; foreach (var builder in builders) { var car = factory.Build(builder); Console.WriteLine($"Samochód zamówiony przez " + $"'{builder.GetType().Name}': " + $"\n ------------------------------------" + $"\n Konie mechaniczne: {car.HorsePower}" + $"\n Najbardziej ceniony za: {car.MostImpressiveFeature}" + $"\n Maksymalna prędkość: {car.TopSpeed} km/s \n"); Console.ReadKey(); } }
static void Main(string[] args) { var superCarBuilder = new SuperCarBuilder(); var superCar = new CarFactory().Build(superCarBuilder); var lameCarBuilder = new LameCarBuilder(); var lameCar = new CarFactory().Build(lameCarBuilder); // (could choose to put builders in a collection and iterate over each, calling .Build() on each) }
/// <summary> /// The Client /// </summary> static void Main(string[] args) { var superBuilder = new SuperCarBuilder(); var notSoSuperBuilder = new NotSoSuperCarBuilder(); var factory = new CarFactory(); var builders = new List <CarBuilder> { superBuilder, notSoSuperBuilder }; foreach (var b in builders) { var car = factory.Build(b); Console.WriteLine($"The car requested by is {b.GetType().Name}:\n--------------------------------------------- " + $"\nHP: {car.HP}\nIpmressive Feature: {car.MostImpressiveFeature}" + $"\nTopSpeed: {car.TopSpeedMPH} mph\n"); } }
static void Main(string[] args) { var superCarBuilder = new SuperCarBuilder(); var notSoSuperCarBuilder = new NotSoSuperCarBuilder(); var carFactory = new CarFactory(); var carBuilders = new List <CarBuilder> { superCarBuilder, notSoSuperCarBuilder }; foreach (var builder in carBuilders) { var car = carFactory.build(builder); Console.WriteLine("The Car requested by " + $"{builder.GetType().Name}: " + $"\n--------------------------------------------------" + $"\nHorse Power: {car.HorsePower} " + $"\nImpressive feature: {car.MostImpressiveCarFeature} " + $"\nTop Speed: {car.TopSpeedMPH} mph\n"); } }
static void Main() { CarBuilder basicCarBuilder = new BasicCarBuilder(); CarBuilder superCarBuilder = new SuperCarBuilder(); List <CarBuilder> builders = new List <CarBuilder>() { basicCarBuilder, superCarBuilder }; CarDirector director = new CarDirector(); foreach (CarBuilder builder in builders) { Car car = director.Build(builder); Console.WriteLine($"Car Built By: {builder.GetType().Name}"); Console.WriteLine($"Top Speed: {car.TopSpeed}"); Console.WriteLine($"Horse Power: {car.HorsePower}"); Console.WriteLine(); } Console.Read(); }