Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
Sergey Alexandrovich Kryukov 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 21-Nov-12 20:39pm    
just look at the section on DIP. its the first example in that section.
Sergey Alexandrovich Kryukov 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 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900