Talk:Dependency injection/Archives/2012/October
This is an archive of past discussions about Dependency injection. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Major rewrite (mea culpa)
The page seems to have been idle for a while, and I found the original article to be quite unhelpful. Surprising, since I am a professional working in an environment where dependency injection is used routinely.
The page was rewritten with the following objectives in mind: define the pattern right up front in the introduction; try to move toward more concrete definitions and terminology; feature the importance of dependency injection in unit testing more prominently.
The use of concrete objects (Cars and Engines) in code examples is also -- I think -- very poor practice. Sorry. There are no "Cars" or "Engines" in real software development. It's an abuse of the "object" in object-oriented programming. So I rewrote that too.
Remaining things to do that would make a useful addition to the page: discussion of popular dependency injection frameworks (e.g. Spring, or MEF) would be useful. Maybe even a attempt at compilation of major and minor dependency injection frameworks.
The discussion of advantages and disadvantages needs a complete rewrite as well. Previous postings in the talk page would make a good starting point. Edrowland (talk) 22:41, 16 November 2011 (UTC)
- Error/Typo in Example Code: The Interface "IAutomatedStockTrader" should declare the method "executeTrades()" and not "makeTrades()". BTW, thanks for the much clearer rewrite. --77.188.70.229 (talk) 13:28, 19 November 2011 (UTC)
- Are the following four lines correct? I know it is a conceptual example, but conceptually it seems you should be registering an object with the dependency manager rather than two types.
DependencyManager.register(
typeof(IOnlineBrokerageService),
typeof(MockBrokerageService));
DependencyManager.register(
typeof(IStockAnalysisService),
typeof(MockAnalysisService));
75.87.186.225 (talk) 21:35, 12 July 2012 (UTC)
- In Java, there is no
typeof
keyword or operator or standard API method. I don't know the specific signature ofDependencyManager.register
, but probablytypeof(IOnlineBrokerageService)
should be replaced byIOnlineBrokerageService.class
, as should be in the whole article as long as the code examples are supposed to be Java. --Leo141 (talk) 09:10, 16 July 2012 (UTC)
- Sorry for not knowing the markup. I was looking at this today in the context of Ruby. Dynamic, duck-typed languages do benefit from dependency injection. The term most recently has been popularized in the Ruby community by Sandi Metz.
- However, DI in a dynamic language is a very different beast than in a statically typed language. Most particularly, it's really dangerous to provide a Java example without an example in a language like Ruby. Jamis Buck, a well know figure in the Ruby community, chronicled his experience writing two DI frameworks in Ruby. His conclusion was that DI frameworks are not appropriate for Ruby specifically, nor other dynamic languages generally. His article can be found at http://weblog.jamisbuck.org/2008/11/9/legos-play-doh-and-programming — Preceding unsigned comment added by Hamannp (talk • contribs) 02:08, 25 October 2012 (UTC)