3 ms·
You use a factory when you have code that needs to create something but shouldn't determine the details of their creation. If you want to create enemies from m
by jayd16 7y ago
You use a factory when you have code that needs to create something but shouldn't determine the details of their creation. If you want to create enemies from multiple places (seems common) you don't want to have to refactor every place when you change something about the creation or pooling.
- bogdanoff_2 7y agoYes, if you determine that creating your objects requires passing in state or using some logic that you don't want to put in the constructor, then using a factory or factory function makes sense. However that has nothing to do with creating a dynamic number of enemies. Object pooling is a good point actually.