Tuesday, May 31, 2016

Mocking Dependencies With Generics

Elmar Kretzer (via Andy Bargh):

You can inject code dependencies in a transparent way by using generics and typealias.


Those dependencies are loosely coupled, but in my opinion they belong together in a semantic way.


We end up with:

  • a generic ModelFor taking a type conforming to Environment
  • a typealias Model representing ModelFor<RealWorld>
  • no code necessary to manage the dependencies with properties or whatever

Comments RSS · Twitter

Leave a Comment