Tutorials‎ > ‎Design Principles‎ > ‎

Low Coupling

Design Principles

Coupling is a measure of how strongly one element is connected to, has knowledge of, or relies on other elements. An element with low (or weak) coupling is not dependent on too many other elements. A class, for example, with high (or strong) coupling relies on many other classes. Such classes may be undesirable; some suffer from the following problems:
  • Forced local changes because of changes in related classes.
  • Harder to understand in isolation.
  • Harder to reuse because its use requires the additional presence of the classes on which it is dependent.
As mentioned above, low coupling is desirable because a change in one area of an application will require less changes throughout the entire application.  In the long run, this could alleviate a lot of time, effort, and cost associated with modifying and adding new features to an application. Coupling not only applies between classes in an application but also between layers in an application.  Within each layer you want low coupling and between layers you want low coupling. The key rule to reduce coupling is to minimize the number of dependencies from class to class and layer to layer. In general, if you need to assign a new responsibility to an object that needs to be an information expert on class X, first look to assign the responsibility to objects that are already information experts on class X.  This will keep coupling low. Low Coupling is an evaluative pattern, which dictates how to assign responsibilities to support low dependency between classes and reduce impact in a class by changes in other classes.

To summarise low coupling:
  • Clear boundaries between tiers
  • Program against interfaces, not classes
Comments