When to decide to introduce interfaces (pure abstract base classes) in C++?

Posted by Honza Brabec on Programmers See other posts from Programmers or by Honza Brabec
Published on 2013-07-03T12:46:46Z Indexed on 2013/07/03 17:18 UTC
Read the original article Hit count: 310

Filed under:
|

Assume that you are developing a functionality and are 90% sure that the implementation class will stay alone. If I was in this position in Java I would probably not use the interface right now to keep the things simple. In Java it is easy to refactor the code and extract the interface later.

In C++ the refactoring is not always so easy. It may require replacing values with smart pointers (because of the introduction of polymorphism) and other non-trivial tasks.

On the other hand I don't much like the idea of introducing virtual calls when I am 90% sure they won't be needed. After all speed is one of the reasons to prefer C++ over simpler languages.

© Programmers or respective owner

Related posts about c++

Related posts about object-oriented