implement factory pattern for products with conditional compiling
问题 I'd like to implement factory (or some other pattern) in a way that will allow me to compile the code without introducing type dependency. enum CarType { BMW, PORSCHE, MERC }; class CarFactory { public: static Car* create(CarType type) { switch(type) { case BMW : return new BMWCar(); case PORSCHE : return new PorscheCar(); default : return new MercCar(); } } }; When I compile CarFactory, I need to include BMWCar, PorscheCar and MercCar as a part of my compilation/linking unit. The way my