aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Is there any difference between singleton and static class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Is there any difference between singleton and static class?" Watch "Is there any difference between singleton and static class?" New topic
Author

Is there any difference between singleton and static class?

Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
Assume that we have a class with full of static methods. To access this methods we don't need to create a object.

Is there any difference between singleton object and this class?
which is better and how?
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Singleton isn't about not creating an instance, Singleton makes sure that there is only one instance of a class (like a FileSystemManager object for example).
A class with only static methods is usually called a "Utility class".
Avishkar Nikale
Ranch Hand

Joined: Aug 06, 2010
Posts: 173
John Todd wrote:Singleton isn't about not creating an instance, Singleton makes sure that there is only one instance of a class (like a FileSystemManager object for example).
A class with only static methods is usually called a "Utility class".


John,

Nice explanation. Concise & to the point.

Thennam,

Singleton is one of simplest OO pattern to explain but one of the rather difficult one to implement (depending on your system, class loaders etc).

As far as comparison goes as John said, it is apples vs oranges, they have completely different tasks in a system.


Regards,
Avishkar Nikale
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
While there are usually many more efficient ways to design OO applications without using the Simpleton design pattern, the pattern does have considerable benefits when compared to class operations, e.g. more flexibility.
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Simply because if you use an interface for your class you need an instance which implements that interface. This is for me the main reason for using the singleton pattern. I have some utility classes but I don't want the rest of my code to know the implementation details but I don't want the create lot of objects. So I use the singleton pattern for generating 1 object which implements the interface.


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Is there any difference between singleton and static class?