Possible Duplicate:
What is the performance cost of having a virtual method in a C++ class?
Is it true that interfaces slow down programs? I have heard that this is the case because during running time each during each usage of an object implementing this interface the decision has to be made which class implementing the interface this object belongs to.
I am especially interested in an answer for C++, but also in general. And if this is true, some numbers would be helpful, too.
Thank you very much!
Although Billy points out that this is a lot like the other post on SO, I think it’s not exactly the same… mainly because of the way this question is worded.
Because Olga talks about a “decision”, I almost thought that she was getting mixed up between using interfaces vs. using a derived class, and determining if the pointer to the object is of a particular class via dynamic_cast.
If you are talking about using dynamic_cast, then from what I understand (and this is not based on concrete performance numbers), you will get a pretty significant performance hit.
If you are talking about using interfaces, well, then I feel that the minor hit in doing a vtable lookup and extra call(s) is far outweighed by a better software design.