• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

service locater

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the use of singleton calss in service locater? cant we use without a singleton class in service locater ?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Among other things, the ServiceLocator holds "home" objects for various remote services. Part of the idea is to create only one home object for a given service saving a little time & memory compared to making new ones all the time. If you had multiple ServiceLocators, they would probably each hold one home for a given service, back to wasting that little bit of time & memory. So Singleton is a way to have ONE container that holds a reference to each home.
Plenty of people think singletons are rarely or never necessary and are badly overused. That could be true, but I like them for situations like this where you want to have exactly one of something. (Caution: we might get one per JVM or per class loader or something else not precisely equal to one, but it should be CLOSE and better than say a million of em.) ServiceLocator might have worked just as well with all static variables and static methods instead of a singleton mechanism.
Hope that made sense! Let us know if not!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic