I'm working on a game which has different items which all have different behavior. All items can be improved by buying different upgrades for different aspects of the item. I save the player's data in a MongoDB. This data includes an array of documents. Each documents represents one item and contains at least a String holding the item's name. This makes it possible to identify the type and instantiate an object of that type when the player wants to use it.
My plan was to use some sort of service locator to map the names to the factories of the specific item. After reading a lot of similar questions spread across StackExchange I learned that service locator is generally considered an anti-pattern.
The question that comes up now is: What should I do instead? I plan to move the items out of the core and create different expansion packets, which would add new items. These would be added to the service locator, so I somewhat need it or a good alternative to it.
Is my case one of these special cases where service locator isn't the bad anti-pattern which should be avoided or is it considered bad practice even in this kind of usage? What are my possible alternatives?
Thank you for your help!
Aucun commentaire:
Enregistrer un commentaire