This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
where the string connection is currently a file location but in the future can be an sql statement. Using the parameter, it calls on the scheme to get the DAO. Would it be correct to say that my constructor has dependency injection?
Would it be correct to say that my constructor has dependency injection?
Hum... no, like my good buddy Roel showed above.
Other than that, the second approach you showed is very inflexible. If the data source changes in the future, then you'll have to open your BusinessService class to modify your code so it works correctly. Today, we have to deal with a .db file, but tomorrow, it could be a database. So, the first approach is much better.
If you have a factory or your Data class is a singleton, then you can obtain it, for instance, in the constructor of your BusinessService class. But receiving a String in the business component is not a good idea.