principles:dependency_inversion_principle
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
principles:dependency_inversion_principle [2021-09-02 12:22] – old revision restored (2021-05-19 11:18) 65.21.179.175 | principles:dependency_inversion_principle [2021-10-18 21:23] – old revision restored (2018-12-08 15:34) christian | ||
---|---|---|---|
Line 68: | Line 68: | ||
/* * [[wiki: | /* * [[wiki: | ||
- | [[wiki: | + | [[wiki: |
/* * [[wiki: | /* * [[wiki: | ||
Line 78: | Line 78: | ||
* [[Low Coupling]] (LC): LC aims at reducing the dependencies to other modules. One way to do so is to only depend on abstractions. DIP is about this aspect. | * [[Low Coupling]] (LC): LC aims at reducing the dependencies to other modules. One way to do so is to only depend on abstractions. DIP is about this aspect. | ||
+ | * [[Dependency Abstraction]] (DA) ((Andreas Zwinkau: [[http:// | ||
==== Specializations ==== | ==== Specializations ==== | ||
Line 98: | Line 98: | ||
==== Example 1: Furnace ==== | ==== Example 1: Furnace ==== | ||
- | An example for a high-level module is a regulator module of a furnace. The classical approach would result in the regulator depending on a thermometer and a heater. in such a case it would not be possible to reuse the regulator module for regulating the fluid level of a reservoir or the speed of a car. A DIP-compliant solution would result in the regulator just depending on a sensor module and an actuator module and thermometer and header implementing these \lstinline!interfaces!. By doing so thermometer, | + | An example for a high-level module is a regulator module of a furnace. The classical approach would result in the regulator depending on a thermometer and a heater. in such a case it would not be possible to reuse the regulator module for regulating the fluid level of a reservoir or the speed of a car. A DIP-compliant solution would result in the regulator just depending on a sensor module and an actuator module and thermometer and header implementing these '' |
This example is taken from (({{page> | This example is taken from (({{page> | ||
+ | ==== Example 2: Client Repository ==== | ||
+ | Let's say the high-level module (your business logic), wants to be able to add or remove users to the database. Instead of it talking to the database directly, it defines an interface called ClientRepository which contains the methods the business logic needs. Then a MySQLClientRepository concretion, implements that interface and uses a database library to submit the queries. Since the interface is decided by the business logic, the high-level policy is protected from changes in the database library. More over, since the interface was defined by the business logic, it does not reveal anything about the underlying implementation, | ||
===== Description Status ===== | ===== Description Status ===== | ||
/* Choose one of the following and comment out the rest: */ | /* Choose one of the following and comment out the rest: */ | ||
Line 117: | Line 119: | ||
* [[wp> | * [[wp> | ||
+ | ===== Discussion ===== | ||
+ | |||
+ | Discuss this wiki article and the principle on the corresponding [[talk: |
principles/dependency_inversion_principle.txt · Last modified: 2021-10-18 21:23 by christian