Service Locator Pattern

The service locator design pattern is used when we want to locate various services using JNDI lookup. Considering high cost of looking up JNDI for a service, Service Locator pattern makes use of caching technique. For the first time, a service is required, Service Locator looks up in JNDI and caches the service object. Further lookup or same service via Service Locator is done in its cache which improves the performance of application to great extent The Service Locator Pattern is to transparently locate business components and services in a uniform manner.
Spring Framework internally uses Service Locator pattern to manage Dependency Injection.These days, Service Locator isn’t of much use anymore, except in very small proprietary projects. For the rest, use a good dependency injection framework like spring or guice.
Let's discuss how Service Locator Pattern transparently locates business components and services in a uniform manner.
Reading theory is always boring so maybe we can jump to source code section to understand this pattern step by step implementation.
This pattern is divided into a number of sections for simplicity like problem, forces, solution etc.
Table of contents
Problem
Forces
Solution
Structure - Class Diagram, Sequence Diagram
Participants and Responsibilities
Implementation
Consequences
Applicability
References

Read more on http://www.javaguides.net/2018/08/service-locator-design-pattern-in-java.html

Comments