What is meant by the "dependency inversion principle" in object-oriented programming? What does it do?
What does "dependency inversion principle" mean in OOP?
964 views Asked by bunty At
2
There are 2 answers
0
dj_segfault
On
The main reason for using dependency inversion is to allow for different implementations of those lower-level modules to be selected either at compile-time in the application or at runtime by configuration. This is a big win for testing because it allows you to completely isolate the code being tested and use mock objects.
Another way this is a huge help is for client deployments. Let's say you have different customers with different auth systems, or different databases, or reporting systems, or whatever. You can configure their system at deployment time by changing an XML file to choose the right implementations of those components to load, with no code changes at all.
Related Questions in OOP
- How do I apply the interface concept with the base-class in design?
- Creating multiple instances of a class with different initializing values in Flutter
- System.InvalidCastException while inheriting a class
- How to add logging to an abstract class in php
- creating cutscenes using OOP and pygame
- What effect does the `virtual` modifier have on an interface member?
- How to pass the value of a function of one class to a function of another with the @property decorator
- Creating a C++ Class Instance for every server request?
- Dart OOP programming
- Containing Object Design
- Clean architecture/OOP and optimization: how to organize for classes with same logic
- How to get 5 LEVEL hierarchy users from database using PHP and MYSQL
- TypeError: unsupported operand type(s) for /: 'property' and 'complex'
- How can I refer to this metaclass inside a metaclass without specifying its name in the code?
- Why customed "-eq" do twice in Powershell?
Related Questions in DESIGN-PRINCIPLES
- Domain driven design CQRS with multiple aggregates and bounded context
- Difference between REP(Reuse/Release Equivalence Principle) and CRP (Common Reuse Principle)
- Is it a good practice to define datatypes in `__init__.py`?
- How to prevent coupling between our code and third party libraries?
- Is there a principle "inverted" to single responsibility? I.e. to collect all responsibilities related to certain task in one place?
- How should I use Factory method design pattern that follows Dependency Inversion Principle
- Is it bad practice to mix SubTyping and Overriding?
- “Never alter or delete a user’s work without them knowing” - is there a name for this software design principle?
- Design pattern for encapsulation of functions that draw / write an object
- When should I throw exception vs. return error ActionResult in ASP.NET Core Web API project?
- Spring application events without extending ApplicationEvent
- When we use class methods as setter to input object
- How to implement the Open-Closed Principle in error handling for new error types?
- Identify the best architecture for sending different types email in ASP.NET Core
- Best practice to create nested objects
Related Questions in PRINCIPLES
- Is it okay to throw exceptions and errors from not controller or request class in Laravel or in general?
- class object definition - programming jargon:
- QT infinite view on model
- When do I need to start grouping my functions into classes?
- How does Node.js process incoming requests?
- How could virtual properties in model classes violate the persistence ignorance principle?
- Why this boolean doesn't give me the right value?
- SOLID - Violated Open-Closed principle
- Java Swing Listeners
- C++ Priciples and Practice Exercise - Finding primes from input value n
- Where and how do SLAM algorithms keep a map?
- Number of ways a program can execute on a sequentially consistent architecture
- C# overloading operator==: Return something else than bool
- Are there reasons to avoid bit-field structure members?
- How to gracefully integrate unit testing where none is present?
Related Questions in DEPENDENCY-INVERSION
- Do we need IoC containers in typescript if ts-mock-imports exists
- How to Choose Specific Concrete Implementation of Interface with Dagger Hilt
- How to Implement Dependency Inversion and Interface Segregation for a Concrete Class that Needs to Be Initiated?
- Is Dependency Inversion Necessary to Ensure Decoupling between Caller and Callee?
- based on dependency inversion principle, How do I access functions that are only in my child class and not in my interface?
- DI/HttpContext in custom ConsoleFormatter
- Dependency Inversion in DDD architecture
- How should I use Factory method design pattern that follows Dependency Inversion Principle
- Separate data and domain layers in a multi-module project and follow D in Solid
- Does using Service interface in Spring Boot REST Controller represent Dependency Inversion principle?
- What's the correct way to implement dependency inversion with single-method interfaces in Dart?
- Is it possible to provide a null implementation when registering something on Flutter's GetIt?
- Does it make sense to apply dependency inversion if it requires instantiating a dependency with default values to update them later?
- how to create unit tests for a graphl resolver mocking the controller without using class
- Dependency inversion and clean architecture with TypeScript
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
In object-oriented programming,
the dependency inversion principle refers to a specific form of decoupling where conventional dependency relationships established from high-level, policy-setting modules to low-level, dependency modules are inverted (e.g. reversed) for the purpose of rendering high-level modules independent of the low-level module implementation details.
The principle states:
A. High-level modules should not depend on low-level modules. Both should depend on abstractions.
B. Abstractions should not depend upon details. Details should depend upon abstractions.
Source