April 2018
Intermediate to advanced
246 pages
6h 11m
English
Interface injection defines a way by which the dependency provider should talk to a client. It abstracts the process of passing dependency. The dependency provider defines an interface that all clients need to implement. This method is not so frequently used.
Technically, interface injection and setter injection are the same. They both use some sort of method to inject dependency. However, for interface injection, the method is defined by objects which provide the dependency.
Let's apply interface injection to our balance sheet module:
public interface IFetchAndExport { void setFetchData(IFetchData fetchData); void setExportData(IExportData exportData);}//Client class implements interfacepublic class BalanceSheet implements ...