Static or instance calling?
Monday, November 08, 2004
I have always debated if static method calls are OO or procedural programming. I think there is a middle ground for this one.
I also had an interest to know if there was a performance hit by calling one or the other. So I wrote this article/blog entry called
Using static or instance methods, together with a small test class.
The sample code is very generic and perhaps too small to come to any conclusion. So don't take my sample as anything scientific or based on any long-term statistics. This is only a sample to convince myself that static methods are a bit faster to execute than instance method. I.e. there is no instance of the class, for one.
I'm sure there is some code out there that will give better performance with either static or instance calling. In the end, it's the design that should drive your choice of method calling. Static method calls don't look too OOish, however, they have a place in OO design.
Comments:
http://www.jroller.com/page/alanli/20041110#hello_world