• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singleton's static method(s) & the need for getInstance()

 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am thinking out load and experience looking for alternatives and trying to learn the most out of this assignment, so please don't mind me.


if the Singleton has got only few methods, would it be better to make those methods static (if doable without problems) and eleminate getInstace()?

probably for maintainability reasons it is not better since there might be a chance of the need of a new method that can't be static.

what about performance, would it hurt the performance to having many static methods?
 
rinke hoekstra
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One difference between singleton and a class with only static methods is, that a singleton can use instance fields to keep its state. A class with only static methods cannot do so.
[ August 28, 2007: Message edited by: rinke hoekstra ]
 
Jar Jaquiso
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Musab,

I don't think it would affect performance but personally I prefer having a static getInstance() method.

If you have all your methods static you lose the possibility to subclass thus resulting in a not-so-flexible application.

Anyway I suppose it's a matter of taste. I personally think that it's nice to keep the possibility to subclass just in case.

Jar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic