Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the actual advantage of Singleton program

 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • 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
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15483
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • 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.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • 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>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic