D.1.7 Outline the need to reduce dependencies between objects in a given problem.
"A dependency is a relationship that signifies that a single or a set of model elements requires other model elements for their specification or implementation. "
A dependency indicates a semantic relationship between two model elements (or two sets of model elements). It relates the model elements themselves and does not require a set of instances for its meaning. It indicates a situation in which a change to the target element may require a change to the source element in the dependency.
"Dependency relationship signifies that one object is dependent on one or more objects in order to function. In other words, the implementation of an object depends on one or more other objects. This occurs when one class links to one or more other classes. The dependency relationship is represented with a dashed arrow. The arrow leaves the object that depends on the object that the arrow points to."
Example
"Whenever a class A uses another class or interface B, then A depends on B. A cannot carry out it's work without B, and A cannot be reused without also reusing B. In such a situation the class A is called the "dependant" and the class or interface B is called the "dependency". A dependant depends on its dependencies."
Dependencies decrease the ability of code reuse, as well as increase maintenance overheads. Code reuse means the use of existing code to build new software. Code reuse takes place so that there is no need to reinvent the wheel in every project. Code reuse allows the developer to use the same code again if the same functionality is needed.
Changes in one class in a dependency will/may affect the other class(es) in this dependency;
This may cause programs using the second class not to function (correctly)/require modifications to the second class to avoid problems;
Example
if the variables in the Code class changed type then the TrainCompany etc methods would have to be changed;
(Less dependencies lead to) reduced maintenance overheads;
As a programmer editing one class would not have to be concerned with other classes / allows programmers to focus just on the class they are writing;
Examples
A Stereo System is stable.
objects not dependent on one another
not convenient to move
easy to repair or buy new component
easy to purchase components from different vendors
A TV is convenient
all objects in one box and dependent on each other
convenient to move
difficult to maintain and we are often forced to repair or buy complete unit
difficult to purchase components from different vendors
NOTE: System designers must decide on class designs that are stable or convenient.