Service locator is quite similar to the singleton pattern, as it can be used to provide global access. The main difference is, that with service locator we are not going to try to control the life cycles of the services. The pattern has only a single responsibility, to locate a service and return it to the client. For this task, we will have a look at two different implementations of this pattern.
Implement a service locator reliable service locator. For this, we will presume, that there is a need for services named PlayerProfile, MapFactory and ObjectPool. As we do not have implementations of these services you should provide null services instead. See Game Programming Patterns for the description of a null service.
Requirements checklist
Create a service locator, which can provide access to any class. While this implementation is very powerful, it also has a major downside. Using this approach it is up to the client classes to check for null references.
Requirements checklist