A common mistake when programming C ++ (and other object-oriented languages) is the excessive use of inheritance. Interfaces are inherited correctly. The reason is that the power of interfaces is to process objects of a different type in another system, as if they were of the same type. Triangle and Circle can be both Shapes, for example, and can be transferred to the graphics engine for drawing on the screen.
The reason interfaces are “better” than inheritance, which also includes inherited functionality, because it quickly becomes very difficult to understand what the class really does to debug it and make sure that the internal state of objects cannot be destroyed using external methods .
The need for this type of structure, where you use interfaces more than sporadically, is difficult to motivate in a small example, but it becomes apparent when projects become large. In addition to creating things like I describe above, they are also good for making it easier to test the program, because instead you can replace the implementation of part of your program (say, accessing the database for instace) with a shaded implementation, and thus allow you to write automatic tests that check other parts of the program (for example, data processing)
There is no reason to choose an interface for direct access to members, and not vice versa, since you are calling methods that are virtual. This, however, is a very slight decrease in performance in most cases.
Meros source share