Using Interfaces as a Contract
Another way to think about using interfaces with dependency injection is that they are fulfilling
a contract. Our interface is a contract between the supplier, our code instantiating a dependency
and injecting it, and our client, the class with a dependency need. The contract is fulfilled when
the correct object is injected into the object.
This concept has been described as programming by contract. It’s an interesting way to think
about interfaces and dependency injection.
Do'stlaringiz bilan baham: |