Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Replacing Singleton Design Pattern

 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic