Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does coding towards an interface rather then an implementation imply a performance hit?

In day to day programs I wouldn't even bother thinking about the possible performance hit for coding against interfaces rather than implementations. The advantages largely outweigh the cost. So please no generic advice on good OOP.

Nevertheless in this post, the designer of the XNA (game) platform gives as his main argument to not have designed his framework's core classes against an interface that it would imply a performance hit. Seeing it is in the context of a game development where every fps possibly counts, I think it is a valid question to ask yourself.

Does anybody have any stats on that? I don't see a good way to test/measure this as don't know what implications I should bear in mind with such a game (graphics) object.

like image 646
Boris Callens Avatar asked Dec 05 '22 06:12

Boris Callens


1 Answers

Coding to an interface is always going to be easier, simply because interfaces, if done right, are much simpler. Its palpably easier to write a correct program using an interface.

And as the old maxim goes, its easier to make a correct program run fast than to make a fast program run correctly.

So program to the interface, get everything working and then do some profiling to help you meet whatever performance requirements you may have.

like image 66
PaulJWilliams Avatar answered Feb 15 '23 22:02

PaulJWilliams