• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Performance Doubt

 
Animesh Shrivastava
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,
I have a simple doubt regarding performance. Suppose i am having a common class which contains some common methods.
Now i need to use common methods in my specific class. Which way is better?
1) Extend the super class which contains common methods and there by we can just call those methods.
2) The commom class contains methods which are public static, so just call them by Class.methodname

Thanks & Regards,
Animesh
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As with every performance question: it depends on the context of how you are using these classes. If you want to find out, write both and prerformance test them.

However, performance should almost never be a condsideration when creating your static model. Design classes based on their function, not how they may perform.
 
Vijayendra V Rao
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The decision of extending a class should be based on whether the "specific" class that you are talking about would make any design sense by being made as a sub-class of the other class (which has those methods). However, if you are thinking of inheritance just in order to use those methods, then that would be just a "quick-and-dirty" inheritance. Simple thing...don't go for it because you yourself will get confused when you are trying to make sense out of the whole code at a later point (not to mention your fellow programmers ;-) )

If both the classes have no hierarchical sense, then go with the second method. If you have declared the methods to be static, then they will neither be stored in the heap nor the stack nor the constant storage...they go into a different type of storage, in the RAM, called "static storage". So I don't think this approach will be a hit on the performance.
 
Lionel Badiou
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Animesh,

In my experience, best perforances come from improved algorythms and rarely from "technical tricks". As a programmer, you want surely know more on how java compilers manage your code. However, don't expect too much time gain using this knowledge ;-)


Best regards,
 
Animesh Shrivastava
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for the help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic