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