Static or not?
Me and my collegue were having a discussion on static methods in Java. My collegues argument for static methods went this way
* They are fast [because of compile time binding]
* No need to instantiate classes, makes memory conservation
And my sole point against static methods
* No flexibility , if you want to change behaviour of the class partly,can't override .
I think only when absolutely convinced that the methods are NOT going to change, should one use static methods. A good example quoted by everyone is Math class. abs() is always abs().
If I need subclassing, changing method behaviour I would settle for nonstatic methods.
Me and my collegue were having a discussion on static methods in Java. My collegues argument for static methods went this way
* They are fast [because of compile time binding]
* No need to instantiate classes, makes memory conservation
And my sole point against static methods
* No flexibility , if you want to change behaviour of the class partly,can't override .
I think only when absolutely convinced that the methods are NOT going to change, should one use static methods. A good example quoted by everyone is Math class. abs() is always abs().
If I need subclassing, changing method behaviour I would settle for nonstatic methods.

0 Comments:
Post a Comment
<< Home