Low Coupling and High Cohesion in Software Design

Connect with

Low Coupling High Cohesion in Software DesignLearn Low Coupling High Cohesion in Software Design and its different aspecects, which help in disigning issue. Single Responsibility principle.

In the previous article, I tried to describe Cohesion and SRP ( Single Responsibility Principle), now I pick the importance of High Cohesion and Low coupling in the software engineering specially while designing a component of the software.

1. Overview of Low Coupling High Cohesion

As we know, software design is a creative process and it’s art rather than science, just like designing anything else. In an analysis of software design, many factors have to consider but out of all these two (coupling and cohesion) play an important role.

“As per my understanding, the best design is a flexible one not a perfect one.”

Why I said this because software functionalities keep evolving according to time. We know that today’s best practices can be tomorrow’s worst practice or anti-pattern. I assume that today, we design a component by considering today’s requirements and tried to carry forward today’s SLA (Service Level Agreement). If our design is flexible one so that tomorrow we can extend those else very difficult to refactor legacy code.

2. Low Coupling in Software Design

“The degree of interdependence between two modules”

We aim to minimize coupling to make modules as independent as possible. ​How can we achieve low coupling can be achieved by eliminating unnecessary relationships, reducing the number of necessary relationships, and easing the tightness of necessary relationships.

There are two type of coupling:

  • Afferent coupling: Afferent means incoming. A class afferent couplings is a measure of how many other classes use the specific class.
  • Efferent Coupling: efferent means outgoing. A class efferent couplings is a measure of how many different classes are used by the specific class.
class Foo {
    Cool c;

class Bar {
    Cool c;

class Cool {
    // ...

Here, Foo and Bar each have one efferent coupling, and Cool has two afferent couplings.

At a Glance: Low Coupling High Cohesion

  • Coupling means– one object depending on other object
  • Two elements are coupled, if
  • One element has association (aggregation/composition) with another element.
  • One element implements/extends other element.

3. High Cohesion in Software Design

Cohesion means “Stick together” as per dictionary, but in software engineering in designing a component, it’s a degree to focus a responsibility to a class.

“There should be one and only one reason to change the class”

This is the SRP (Single Responsibility Principle) but what about Cohesion. Cohesion and Single Responsibility Principle (SRP) goes hands-in-hands.

4. Summary of Low Coupling High Cohesion

  • Try to adhere to the “high cohesion and low coupling” guideline on all levels of your code base.
  • Cohesion represents the degree to which a part of a code base forms a logically single, atomic unit.
  • Coupling represents the degree to which a single unit is independent from others.
  • Classes that adhere to the principle tend to have High Cohesion.
  • It’s impossible to achieve full decoupling without damaging cohesion, and vise versa.

5. References

I hope you enjoyed this post of Low Coupling and High Cohesion in Desing principles, and you can visit design patterns tutorial for more details
Happy learning! 🙂

Connect with

Leave a Comment

Your email address will not be published. Required fields are marked *