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 toEnvironment
- a typealias
Model
representingModelFor<RealWorld>
- no code necessary to manage the dependencies with properties or whatever