Tuesday, May 31, 2016 [Tweets] [Favorites]

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

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment