Forums Register Login

Performance Doubt

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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,
+Pie Number of slices to send: Send
Thanks all for the help
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 697 times.
Similar Threads
doubt in polymorphism
Doubt in threads
doubt
constructor doubt
Doubt
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:36:32.