static void Main(string[] args) { CarFactory[] myCars = new CarFactory[2]; myCars[0] = new BMWFactory(); myCars[1] = new ToyotaFactory(); foreach (CarFactory factory in myCars) { Car product = factory.CreateCar(); Console.WriteLine("Created {0}", product.GetType().Name); Console.ReadLine(); } }
static void Main(string[] args) { var rnd = new Random(); CarFactory factory = null; if (rnd.Next(0, 1) == 0) { factory = new BMWFactory(); } else { factory = new AUDIFactory(); } Assemble(factory.ConstructBody(), factory.ConstructEngine(), factory.ConstructInterior()); }
static void Main(string[] args) { //No Factory Console.WriteLine("No Factory"); Console.WriteLine(); Audi audi = new Audi(); audi.BuyCar("A3"); //Simple factory SimpleCarFactory carFactory = new SimpleCarFactory(); CarStore store = new CarStore(carFactory); store.BuyCar("Audi", "A3"); //Factory Method CarFactoryMethod audiFactory = new AudiFactory(); audiFactory.BuyCar("A3"); CarFactoryMethod bmwFactory = new BMWFactory(); audiFactory.BuyCar("M3"); }