Suppose I have a class A that depends on 3 other classes X, Y and Z, or A uses them with a reference or pointer, or say that A templated to create instances with X, Y and Z does not matter, the key is that for checking A I need to have X, Y and Z.
So, I need to have fakes for A, B, and C. Suppose I write them. Now, how can I easily exchange real and fake objects? I see that this works very easily with templates. To make it work when A depends on X, Y and Z with a reference or pointer, I need the base class to say X_Interface, from which I can inherit X_Real and X_Fake.
So basically, I get 3 times as many classes for every class that should have fake.
Most likely I'm missing something. There should be an easier way to do this. Having the X_Interface base class is also quite expensive since I will use more space and make virtual calls. I think I could use CRTP as I know if its X_Real or X_Fake at compile time, but there still needs to be a better way.
source
share