object orientation – What is the definition of the term coupling?

Question:

What is the meaning of the terms high/loose coupling in object-oriented system development or object- oriented programming (OOP) ?

Answer:

Concept

  • In a global aspect coupling is the degree of dependence between two "artifacts". Where artifacts can be entities, methods, components, tables, whatever is in the other.
  • Low coupling – is when an "artifact" has little or no dependence on others.
  • High coupling – is the inverse of bass obviously, being when an "artifact" has a great dependence on another.

Good Practices (Design Principle)

  • Tight coupling is not considered good programming practice, where your components, "artifacts", will have a high degree of dependency, making it more difficult to maintain and test.*¹
  • Loose coupling, on the other hand, is considered a good programming practice (loose coupling), since with it you keep your components, "artifacts", less dependent on each other, having greater traceability and testability.*¹

*¹ But this is only Good Practice (design principle), it does not mean that you cannot use high degree coupling in your design, because it is unavoidable in some cases. Just be careful to keep your design with as little coupling as possible.

Examples

  • A common example of tight coupling is inheritance , where your entity cannot exist without its base entity. In modeling this is considered the highest degree of coupling. But that does not mean it should not be used, it should only be used with greater moderation, always analyzing whether this high degree of coupling is really necessary.
  • A good practice to reduce coupling is to use other patterns, such as dependency injection , which helps to reduce dependency between layers, entities or modules.
  • To reduce coupling, it is also advisable to analyze your dependencies, checking if they can be removed, or exchanged for another one with a lower degree of dependency (for example, exchanging an inheritance for an aggregation), this will improve traceability and testability. of your project.

Considerations

Coupling is necessary, between different modules, what the standards preach is that it should be as small as possible, always evaluating whether it is necessary to create a certain dependency or whether it can be replaced by a smaller dependency.

Note: The coupling concept is independent of the programming language or technology used in your project. It is a matter of good practice .

Scroll to Top