Does the use of program interfaces decrease?
Possible duplicate:
What is the cost of executing a virtual method in a C ++ class?
Is it true that interfaces slow down programs? I've heard that this is the case, because while each is running, every time you use an object that implements that interface, a decision has to be made about which class implements the interface to which that object belongs.
I am especially interested in the C ++ answer, but in general. And if so, some numbers will be helpful as well.
Many thanks!
a source to share
While Billy notes that this is very similar to another SO post , I think it is not exactly the same ... mainly because of the way this question is phrased.
Because Olga is talking about a "solution", I almost thought she was mixing between using interfaces and using a derived class, and determines if a pointer to an object of a specific class is pointing through dynamic_cast.
If you are talking about using dynamic_cast, then from what I understand (and this is not based on specific performance metrics), you will get pretty significant success.
If you're talking about using interfaces, okay then I feel like a minor hit on vtable lookups and extra calls is far superior to better software design.
a source to share
Yes, but not much and certainly not enough to make a difference if you want the flexibility that interfaces require. (Keep in mind that if you are using the interface heavily, the corresponding vtables bits will end up in L1 or L2 caches, and this will hardly be nearly as bad as you fear.)
a source to share
If you are using an interface pattern (i.e. abstract classes in C ++) then yes, there will be an overhead of virtual function calls. But if you've implemented your own, non-abstract class mechanism to achieve the same, you will also have an overhead, probably more than calling VF. So there is really no extra overhead.