While i was reading factory , abstract factory design patterns on head first design pattern
book. It mentioned about the phrase.
Could you give an basic example and explanation to clarify it.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Dependency Inversion Principle; One of the five Object Oriented Design Principles. Check out the answers to this question; “What is the Dependency Inversion Principle and why is it important?” – there’s some really good information there.
In ‘simple‘ terms, this means that when you rely upon a concrete instance of an object – you’re building a dependency in to your code (albeit without that intention), this then limits the ability to re-use it.
Remember that a Concrete Type is a type of class that can be instantiated and a Abstract Type is a type that cannot; i.e an interface. (See the Taxonomy of Classes)
If you code to a specific concrete class then you will always have the requirement for that class. However, if you code to an interface (an abstraction) then it’s possible to adapt your code to work with any number of classes; as long as they implement that common interface.
So in Java, it means that where possible you should code to an Interface – and avoid making your code depend on specific items. This is often as simple as passing
Interfacetypes as parameters and return types; as opposed to concrete classes.Less dependencies = More ability to re-use code.
More dependencies = More requirements to be able to re-use code.
This will be a re-occuring theme when you’re studying Design Patterns!
Dependency Inversion Principle on Wikipedia.