It's not a secret anymore!*
The moose likes EJB and other Java EE Technologies and the fly likes Replacing Singleton Design Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Replacing Singleton Design Pattern" Watch "Replacing Singleton Design Pattern" New topic
Author

Replacing Singleton Design Pattern

Prakash Dwivedi
Ranch Hand

Joined: Sep 28, 2002
Posts: 452
Hello Friends,

Can we replace singleton design pattern by making all the methods of the class as static and declaring all the constructors as private. This way other classes won't be able to instantiate this class and have to invoke methods using class name only. Also which approach will be better performance wise?

thanks


Prakash Dwivedi (SCJP2, SCWCD, SCBCD)
"Failure is not when you fall down, Its only when you don't get up again"
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

.
Can we replace singleton design pattern by making all the methods of the class as static and declaring all the constructors as private.


Yes you replace singleton by making all methods static. I don't see any performance gain using static methods. I am more comfortable using singleton rather than all-methods-static class implementation even though there is no harm using the latter.


Groovy
 
 
subject: Replacing Singleton Design Pattern
 
Similar Threads
Singleton Examples
final Objects .....
Singletons
Single pattern
how to make single instance of a class?