public void Main() { // I want an economical car, coloured blue... VehicleFactory carFactory = new CarFactory(); IVehicle car = carFactory.Build( VehicleFactory.DrivingStyle.Economical, VehicleColour.Blue); Console.WriteLine(car); // I am a "white van man"... VehicleFactory vanFactory = new VanFactory(); IVehicle van = vanFactory.Build( VehicleFactory.DrivingStyle.Powerful, VehicleColour.White); Console.WriteLine(van); // USING STATIC FACTORY // Create a red sports car... IVehicle sporty = VehicleFactory.Make(VehicleFactory.Category.Car, VehicleFactory.DrivingStyle.Powerful, VehicleColour.Red); Console.WriteLine(sporty); Console.Read(); }
public static IVehicle Make(Category cat, DrivingStyle style, VehicleColour colour) { VehicleFactory factory; if (cat == Category.Car) { factory = new CarFactory(); } else { factory = new VanFactory(); } return(factory.Build(style, colour)); }
public static IVehicle Make(Category cat, DrivingStyle style, VehicleColour colour) { VehicleFactory factory; if (cat == Category.Car) { factory = new CarFactory(); } else { factory = new VanFactory(); } return factory.Build(style, colour); }