File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes what is different in singleton design pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "what is different in singleton design pattern" Watch "what is different in singleton design pattern" New topic
Author

what is different in singleton design pattern

ajay verma
Ranch Hand

Joined: Dec 10, 2007
Posts: 37
as i know,we can't create a object outside a class because we are using a private constructor inside a class.
can any one suggest me the exact definition of singleton with the the help of programming?
kindly suggest me with the exact definition with programming!


thanks
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2046
The 'single'ton uses a single instance instead of two or more, for performance-related reasons.

There is a static method in the singleton class that any outside class can call. Inside that method the class instantiates an instance of its class, and returns it to the outside caller. That is how it is instantiated.

Why singleton? If you have one million transactions a day which can possibly create/instantiate one or more of a certain class, that can put a performance hit on you server. If a single instance can serve all those multi-million transactions, then you improve the resource statistics of your server by a big factor. You only instantiate one, instead of say 5 million! (Memory/resources speaking: what a relief!)
ajay verma
Ranch Hand

Joined: Dec 10, 2007
Posts: 37
hi jesus

as per my request kindly suggest me with the help of programming , in which the particular instance is serving to million of transaction.



thanks again
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by ajay verma:
can any one suggest me the exact definition of singleton with the the help of programming?


Yes, see:
http://en.wikipedia.org/wiki/Singleton_pattern


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
Oo Patterns Uml Refactoring FAQ: Singleton Pattern
[ February 03, 2008: Message edited by: Peer Reynders ]

"Don't succumb to the false authority of a tool or model. There is no substitute for thinking."
Andy Hunt, Pragmatic Thinking & Learning: Refactor Your Wetware p.41
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Note that in addition of only having one instance of a class, the Singleton pattern also provides a global access point (a static getter). This can lead to a nasty coupling problem. Fortunately there are alternative patterns that too only provide one instance, for example the Just Create One pattern.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
chandrakant karale
Ranch Hand

Joined: Nov 21, 2007
Posts: 41
as per my request kindly suggest me with the help of programming , in which the particular instance is serving to million of transaction.


Hi Ajay,
Definition and example .

The Singleton Pattern is a class of which there can be no more than one instance. It provides a single global point of access to that instance.


Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2046
Originally posted by chandrakant karale:


Hi Ajay,
Definition and example .

The Singleton Pattern is a class of which there can be no more than one instance. It provides a single global point of access to that instance.




You will find a good introduction, explanation, code, and issues about the code implementation, in Head First Design Patterns.

The code above has issues and needs improvement. But yes, above is a great example on how to get an idea of what a singleton is.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is different in singleton design pattern
 
Similar Threads
Singleton class, class loader, string literals
To Make a HashMap as a Singleton
2 different types of singleton
cloning Singleton object
Singleton Class and Garbage collection