public static Car GetACarFromFactory(CarEngine engine, CarWheel wheel) { CarGas gas = GetSomeCarGas(); Car runningCar = CarFactory.BuildARunningCar(engine, wheel, gas); // VendingMachine has the knowledge of Engine & Wheel at this point MustDoCarTesting(runningCar); return(runningCar); }
public static Car BuyACar() { CarEngine selectedEngine = new CarEngine(); //Select an Engine you like CarWheel selectedWheel = new CarWheel(); //Select a Wheel you like // Only Caller has the knowledge of Engine & Wheel Func <CarGas, Car> getARunningCarWithGas = gas => CarFactory.BuildARunningCar(selectedEngine, selectedWheel, gas); Car car = CarVendingMachine.GetACarFromFactory(getARunningCarWithGas); return(car); }