• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic