• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

DI vs Abstract Factories

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The lead dev at my work thinks thats

Dependency Injection is for people who can't write Abstract Factories



How would you respond to that?
 
author
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's cute but rather an empty platitude. I'd say it's for people who don't *want* to write, test and maintain factories. There is such an enormous amount of boilerplate code that it saves you.
There are also several other benefits like AOP and modular configuration that you get for free. Of course, one may argue that everything may be done without the use of DI and with these older patterns. But that's like saying why invent cars when we have a perfectly good horse.

Here is a talk my colleague and I presented a couple of months ago explaining some of the differences between factories and DI:
http://www.youtube.com/watch?v=hBVJbzAagfs

Hope this helps =)

Dhanji.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was precisely my response when I saw the question: why would I *want* to write a factory when somebody else already did it for me? All the busywork has been done, I can set properties on the object that's being created, etc. If I *really* need to control object creation I can still plug in my own factory, but still get all the benefits of whatever DI container I'm using. The amount of code I'm responsible for is *greatly* reduced.
 
I child proofed my house but they still get in. Distract them with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic