Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Dependency objects
Reading through:
http://lostechies.com/wp-content/uploads/2011/03/pablos_solid_ebook.pdf
and reading the chapter on DIP (dependency inversion principal, the first example by Jimmy Bogard, is slightly confusing.
 
in his example he takes a class that has two dependencies in the method he wants to use and he then extracts them out as interfaces to decouple these two dependencies from the class. Ok! Good! He then passes the interfaces into the constructor so that he has them to use. Good again.
 
But he doesn't extract out a third object he is passing into the method that he uses in the method, as if this object being passed in isn't a dependency.
 
My question is: if you are passing in a concrete implamentation of an object into anotherobject method, isn't that a dependency, regarless of when or how it is being used in the method?
In order to trully make it decoupled, don't all object being passed around have to be abstracted out as interfaces and passed into the calling object via interface?
Posted 21-Nov-12 14:10pm
Comments
Sergey Alexandrovich Kryukov at 21-Nov-12 20:37pm
   
Why no asking the author? I personally don't see a problem with dependency inversion, but locating this sample in a book...
However, it might be an interesting book. I'm printing it to read later. I'll try to pay attention for this example (please, give me the exact section/page) and will try to tell you what I think. Please, not a firm promise -- sorry. I'll just try.
--SA
chuckdawit at 21-Nov-12 20:39pm
   
just look at the section on DIP. its the first example in that section.
Sergey Alexandrovich Kryukov at 21-Nov-12 20:55pm
   
It looks like this is the example with the description of the problem, not the solution the author suggests...
--SA
chuckdawit at 21-Nov-12 20:58pm
   
look on page 62, the example starts on page 62. The object 'Order' is being passed into the method as a concrete implementation, even after he refactors out the dependencies he still uses 'Order' as a concrete implementation. He doesn't create and pass in a IOrder interface like you would expect to see.
Sergey Alexandrovich Kryukov at 21-Nov-12 21:59pm
   
I see, thanks for clarification. I'll read it later.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 278
1 Nguyen.H.H.Dang 230
2 Maciej Los 205
3 Peter Leow 195
4 arvind mepani 187


Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid