munificent / game-programming-patterns

Source repo for the book
http://gameprogrammingpatterns.com/
Other
4.12k stars 498 forks source link

Subclass sandbox two-stage initialization #361

Open ghost opened 4 years ago

ghost commented 4 years ago

To avoid having to create constructors on each subclass with all parameters needed for the base class initialization, we switched to two-stage initialization. However, directly afterwards, we come up with the createSkyLaunch to wrap both initialization stages in one function. The way we do that, we would need seperate functions for each subclass, each taking all parameters needed for the base class, which means we are back to our initial problem (correct me if I'm wrong here).

Could we apply one of the concepts from the prototype chapter and e.g. make it a template function? (Which btw. only works if the constructors of all subclasses take the same parameters?)