title: C++ or D: idiom to decouple classes without dynamic dispatch?
body: <p>I am a true lover of performance, but I am aware about the importance of execute automated tests too (until better formal verification methods become mainstream).</p>
  
  <p>The drawback is that when you try to design for testability you start to introduce interfaces to represent your dependencies. As you know, interfaces make your invocations dynamic dispatched over that dependency and reduce the optimization opportunities at compile-time.</p>
  
  <pre><code>class MyDependency
  {
      void someMethod();
  }
  
  class MyUnit
  {
      // Concrete type reference of MyDependency allows 
      // to bypass the dynamic dispatch
      this(MyDependency mayBeAMock)
      {
          mayBeAMock.someMethod();
      }
  
      unittest
      {
          // Now how can I get a mock of my dependency without to instantiate it.
          auto dep = someBlackMagic.getMock();
          auto uut = new MyUnit(dep);
      }
  }
  </code></pre>
  
  <p>Does exist a better way to unit test classes without take the dynamic dispatch cost at production. If need, I would can to afford that cost for the unit testing execution but not for the production release.</p>
  
  <p>Im am interested in D and C++ solutions.</p>