Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Outline
layout pattern
title Service Locator
folder service-locator
permalink /patterns/service-locator/
pumlid NSjB3iCm203HgxG7iDdtDeIWX0fZYqzo_MRTtUX9ynOZhPtBzNLchlW0EDxza3nhgs2dQScMdUO0qRenqU6B5xQTGmvh2pFPBM1WF07FSmbnqqcOqu6J_gsNZxvgw0y0
categories Structural
tags
Java
Difficulty-Beginner
Performance

Intent

Encapsulate the processes involved in obtaining a service with a strong abstraction layer.

alt text

Applicability

The service locator pattern is applicable whenever we want to locate/fetch various services using JNDI which, typically, is a redundant and expensive lookup. The service Locator pattern addresses this expensive lookup by making use of caching techniques ie. for the very first time a particular service is requested, the service Locator looks up in JNDI, fetched the relevant service and then finally caches this service object. Now, further lookups of the same service via Service Locator is done in its cache which improves the performance of application to great extent.

Typical Use Case

  • when network hits are expensive and time consuming
  • lookups of services are done quite frequently
  • large number of services are being used

Consequences

  • Violates Interface Segregation Principle (ISP) by providing pattern consumers with an access to a number of services that they don't potentially need.
  • Creates hidden dependencies that can break the clients at runtime.

Credits

Morty Proxy This is a proxified and sanitized view of the page, visit original site.