Spotting use cases for the Service Locator pattern
As a versatile pattern, the Service Locator pattern can be implemented in many systems in our game. Since it is meant to be a centralized point of access to a given service, we can apply it to a variety of situations. Something we should keep in mind is that making many classes rely on a single instance of a class, like in the Singleton pattern, can be dangerous. For instance, if, for some reason, this instance is removed at some point, all the other instances of classes that depended on it will be broken. This is less likely to happen when we have multiple instances with short life cycles. Also, the fact that many user classes rely on a single class is a double-edged sword since if we decide to make a change to said class, we will break all its user classes. That said, in this section, we will explore common use cases for the Service Locator pattern in games.
Localization is an interesting system in games. We need to ensure that...