party code is directly responsible for providing the dependency to the class. As
Nat Pryce
describes it¹⁸
, the use of the term injection can be seen as a misnomer, as it isn’t really injected
into the code, but instead declared as part of the code’s API.
There are two methods of dependency injection that we’ll discuss:
1. Setter injection - Using this method, dependencies can be provided to the object through
a set method on the class, which would be stored for later use in a class member variable.
2. Constructor injection - Using this method, dependencies are provided to the object
through its constructor, which would also be stored for later use in a class member variable.
Do'stlaringiz bilan baham: |