Click here to Skip to main content
Sign Up to vote bad
good
See more: Dependencyobjects
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:10

Comments
Sergey Alexandrovich Kryukov - 21 Nov '12 - 20:37
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 - 21 Nov '12 - 20:39
just look at the section on DIP. its the first example in that section.
Sergey Alexandrovich Kryukov - 21 Nov '12 - 20:55
It looks like this is the example with the description of the problem, not the solution the author suggests... --SA
chuckdawit - 21 Nov '12 - 20:58
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 - 21 Nov '12 - 21:59
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
Your Filters
Interested
Ignored
     
0 Arun Vasu 339
1 OriginalGriff 320
2 Sergey Alexandrovich Kryukov 315
3 Tadit Dash 221
4 CPallini 178
0 Sergey Alexandrovich Kryukov 9,955
1 OriginalGriff 7,589
2 CPallini 4,028
3 Rohan Leuva 3,422
4 Maciej Los 2,949


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