Sure there are side effects. They are non-trivial, in both directions, and most often negligible.
Why do you ask?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
This sorta sidesteps the question, but the biggest concern, and cost, associated with any commercial, enterprise application, is its long-term maintainability and sustainability. A well designed OO application is much more maintainable, understandable, and sustainable. This applies equally to an application that relies heavily on automated testing as well.
There is some overhead to dynamic dispatch of methods. Most OO compilers optimize this well enough that we can usually ignore it. See Virtual Method Table.
Years ago there were heated debates on various VTable algorithms. Microsoft and Borland and other vendors leaprfrogged each other's performance on every release. There was an argument that executing some code in a superclass and some in a subclass forced long jumps instead of short jumps (on Intel anyhow) and greatly increased the probablility of paging. Yawn. Modern compilers and processors and cheap memory have made almost all of this worry go away.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Jul 11, 2001
Originally posted by Stan James: There is some overhead to dynamic dispatch of methods.
Note that the alternative to dynamic dispatch are if- or switch-statements, which arguably have a similar overhead.
If only there were a good tool for actually measuring performance, rather than indulging in meaningless speculations based on vague generalizations...
"I'm not back." - Bill Harding, Twister
Joined: Jun 26, 2002
So what alternative do you suggest? Want to serve as a good example?
The question is immaterial because the performance gains to be had by such microtuning are typically minimal compared to overall application performance. If posters insist on microtuning we should tell them how to measure the performance themselves (i.e. teach them to fish), and let them post the answer. The best service we can provide to junior developers is to get them into the habit of monitoring their code and tuning where appropriate, and not just randomly tuning their code based on whim.
I provided a similar answer in the following faq. Answering such questions with a link to the faq would be appropriate.
I have a link for performance faq's at the bottom of all of my postings. Maybe there could be a whiddled down version for micotuning questions. Item 13 in the faq addresses this in an admittedly harsh way.
12) Don't microtune - An example of microtuning is when you have a web page that takes 1 second to execute, and you notice that you can tune a subset of this pages code and reduce this subsets execution time from 20 ms. to 10 ms. Congratulations, you've cut the execution time of this code in half! This sounds impressive, until you realize you have only trimmed the performance of your overall page by 1% (from 1000 ms. to 990 ms).
This tuning was a waste of time. Your time would have been better spent drinking a beer. Look for changes that give you the biggest bang for your tuning buck.
13) There are bad Performance Tuning Questions - The most common performance tuning questions I see on the java forums are purely academic, and make no substantive difference in real programs. Questions like: "Are statics faster than instance variables?", "Are local variables faster than instance variables?", "Are HashMaps faster than Vectors?", "Are while loops faster than for loops?",...
When we answer such questions without stating that they are purely academic, we do a disservice to the development community by perpetuating the idea that microtuning is the place they should focus their attention.
Joined: Jan 29, 2003
Most of the answers included recommendations to ignore the effects of OO on performance and that was a good theme. A casual decision to do two database queries instead of one or to call a remote service will make far more difference than OO or not.
You can't legitimately talk about "performance" of a piece of code A unless you have an equivalent (i.e. does exactly the same thing) piece of code B to compare it to. So asking about the performance "using OO" is meaningless unless you have an equivalent "not using OO" code that you can talk about.
But nobody has that code, because the question is too high-level for a question that must have low-level things like actual pieces of code to compare. The question is trying to apply a low-level question (performance) to a high-level concept (language design). Hence the exasperated responses from people who are attempting to craft a reply that is simultaneously accurate and polite.