• 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

what is the actual advantage of Singleton program

 
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to know the advantages of singleton Design pattern

I f any one provides a sample program for the implementation of singleton then i can easily understand the aconcept

please provide me the links



thanx in advance


cinux
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try searching for "singleton design pattern" with Google and you'll find lots of information on the singleton design pattern.

Tutorial: Design Patterns
Singleton pattern (Wikipedia)
Simply Singleton - Navigate the deceptively simple Singleton pattern
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With Singleton there will be only one instance of the class per jvm. Most often application specific things can go in singleton. For Ex: if you want to design an application such that application_state (can have values idle, active, on maintenance) need to be shared with many users you can keep this variable in a singleton class.

Advantages are by making a heavy weight class singleton, you are sharing a single instance of that class with many threads. This will save you resources and time.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There isn't an advantage, which is why the singleton is becoming more widely known as the "singleton antipattern", as the design pattern hype subsides. First and foremost, a singleton does not exist, without solid proof of a finite universe, which we don't have. A singleton can exist within a given context; for example, a class loader, a JVM, many JVMs. In practice, I see most singletons implemented throughout a class loader, which is as simple as a global point of access to a hidden static field.

The singleton is usually implemented to prevent the need to pass a callback to clients. Specifically, some state can be updated in a singleton from one point in the application (or more correctly, the singleton context), and can be observed by another point, without either point knowing about each other (though indirectly through the singleton). This pattern can be traced to a requirement defect within a given context - one that we often assume. Since the notion of "design patterns" is losing the spotlight among the newer marketing hype, it is becoming more widely known that behind the gloss, is the opposite of what it was originally portraying itself as. Prefer to pass the callback type, and don't believe the hype - that rhymes I should approach a record label. </geekiness>
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic