to use interfaces or not to use interfaces (where ever possible) ?
I was wondering if its inefficient to use interfaces, considering you would want to squeeze every bit of performance from a game, interface calls are much slower than direct calls.
regards
Fluxtah
[215 byte] By [
Fluxtah] at [2007-12-26]
I am all for interfaces, however I mainly program enterprise applications where I can sacrifice performance for extensibility.
If you consider that interface calls are far slower than direct calls, if your game is all made up of interface calls it would seriously sacrifice performance.
I noticed that space war does not use many interfaces, I wonder if this was the reason.
I suggest reading some interface and base-class design guidelines in the MSDN library[1]. There are many reasons to use and not to use interfaces -- it's going to be largely unique to your application. Otherwise, there are some common recommendations and rarely is performance an issue.
1: http://msdn2.microsoft.com/en-us/library/ms229013.aspx
The main issue I was concerned with was performance, but I was mistaken as the performance factor is practically insignificant, I think I was getting confused with the performance of delegates and dynamic invocation which do suffer a significant performance hit.
Interfaces are fast (as fast as virtual functions), whereas QueryInterface, or dynamic casting (foo as Bar), or delegates/events, are a lot slower. If you know that you'll only ever want to ask for interfaces A, B and C from some base interface I, you would probably do better to expose getA()/getB()/getC() as virtual methods, than trying to do that exposition through some QueryInterface style function.