c++ - Modularity: Using Interfaces or not? -


Since some years, common sense determines that it is better to program against interfaces instead of implementing. It looks really logical for a high-level code, e.g. If I have a complex solver in my application, then something like this looks better:

  isolver * solver = solverFactory.getSolver (); Solver-> Solution of (inputdata);  

instead of

  solver solver; Solver.solve (inputdata);  

In the first code, it is also easier to copy the solver, and thus, in the unit test.

But my question is: At what level is it not to understand the use of the interface anymore, like if I have a complex number class (or string class or whatever) in my application, then Writing it:

  IComplexNumber * complexNumber = complexNumberFactory.create (1,2); // 1 + 2i  

seems more complex than writing (especially about performance):

  complex number complex number (1,2) ); // 1 + 2i  

Therefore, it is important to decide whether any interface should be placed behind and should not be placed behind the interface.

are caused due to an interface when it makes things easier or reduces coupling ( Which is for an interface).

There are reasons to go away from an interface, if it makes things more complicated or kills performance (but the profile is sure). I argue that your IComplexNumber class actually makes class excellence more complicated until you are presenting a MockComplexNumber, but I suspect that such a class would be useful ... and this is probably going to be slow. I'll do it, but I'll measure it.

But do not think that you need to make everything the only way, or your decision is fixed in stone, it is very easy to convert / convert the interface.


Comments