• Post Reply Bookmark Topic Watch Topic
  • New Topic

which 1 to use  RSS feed

 
hitesh parikh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI ALL

I have a scenario where i wont be having any in
instance variables or class variables .
I will be having a few methods where all parameters will be passed i.e we will be having only local variables.
in this scenario what will be most beneficial
do i have all my methods as static
or do i make them instance methods.
rgrds
hitesh
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I, personally, would make them instance methods and implement the Singleton pattern. This way I would be able to subclass the class if necessary. Remember, static methods do not participate in polymorphism, so using them locks you into a fairly unflexible structure.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm lazy, and like static methods sometimes.
Logger.log( "a message" );
is just less typing than
Logger.getInstance().log( "a message" );
Any major problems with the static technique jump out at you?
 
Gayathri Prasad
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I prefer working with instance variables becasue that gives me more flexibilty and Memory is ofcourse no more a scarce asset(Static methods use optimum memory as all would access only one block).
Cheers,
Gaya3
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!