The service locator pattern works more or less the same as to the factory pattern. The service locator can find the existing object and send it to the client rather than create a new one every time, as with the factory pattern. Instead of getting into detail, we will just look briefly at how the service locator works to create objects. The flow of the service locator can be described as per the following diagram:
- Client is relying on Service Locator to find services. Here, service means any kind of dependency
- Service Locator takes the name of the service, and returns the object of service ...