Types of Dependencies
Dependencies and coupling seem to cause the greatest pain in software development. I think it’s useful to look at the types of dependencies that can exist.
Contained Dependencies
A contained dependency is a dependency that a class has, but which is not communicated externally. The class uses the contained object, and so is dependent upon it, but does not propagate the dependency. This is the most benign dependency, as if the dependency breaks, the class may break, but it can not (directly) break other objects.
Direct Dependency
A direct dependency is a dependency which is exposed directly by the class, either in a return value, a parameter, or a base class. Direct dependencies are worse than contained dependencies, as they can directly break classes that use the class under discussion, both in terms of compilation and functionality.
Indirect Dependency
An indirect dependency is a dependency exposed by another dependency. This is worse than direct dependencies, as this is how dependencies propagate, causing the system to become brittle.
Hidden Dependency
A hidden dependency is arguably the worst kind of dependency. A hidden dependency is a contained dependency that can cause side effects, causing other components to fail. Globals are, generally, hidden dependencies.