October 19, 2020

High Cohesion, Low Coupling

How to structure your information to reduce coupling

In this short article I would like to show you one example of High Cohesion and Low Coupling regarding Software Development. Imagine that you have a REST API that have to manage Users, Posts and Private Message between users.

One way of doing it would be like the following example:

As you can see, the RestApplication class is managing the REST API requests correctly, but the issue here is that it also depends on all the other classes and it is managing the logic behind every single action (for example, the logic behind banning an user, reporting a message, sending a message, etc…). This is a clear example of low cohesion and high coupling because it depends heavily on internal classes of other modules. One bad thing about this is: what if some of the internal classes of the other modules changes? Then you will have to change the Application class to make this work.

This RestApplication class is basically a God object.

Instead of that you could use the following example:

The routes are still there in the RestApplication class but instead of it taking care of the logic of every single action, you have delegated it to Service classes in each module. This makes your code more cohesive and less tightly coupled because if some internal class (some DAO class for example) changes other than the service classes themselves, the RestApplication class doesn’t have to care as it isn’t its responsibility to handle the their specific logic any more.

It is known as the Facade pattern and it is a good tool for making your code more cohesive and less tight coupled in your modules.

In summary:

Low Cohesion (BLUE), High Coupling (RED) – BAD

High Cohesion (BLUE), Low Coupling (RED) – BETTER

Frequently Asked Questions

No items found.

Latest Posts

We’ve helped our partners to digitally transform their organizations by putting people first at every turn.

2/12/2024
The Power of Discovery: Ensuring Software Project Success

Effective discovery is crucial in software development to prevent budget overruns and project delays. By conducting discovery sprints and trial projects, businesses can align goals, define scope, and mitigate risks, ensuring successful outcomes.

29/1/2023
Native vs. React Native For Mobile App Development

In this article, we address the advantages and disadvantages of native apps and compare them to those of React Native apps. We will then propose one example of a ‘good fit’ native app and a ‘good fit’ React Native app. The article concludes with a general recommendation for when you should build your application natively and when to do so in React Native.

15/1/2021
Azure Security Best Practices

Adoption of cloud services like Microsoft Azure is accelerating year over year. Around half of all workloads and data are already in a public cloud, with small businesses expanding rapidly and expecting up to 70% of their systems to be in a public cloud within the next 12 months. Are you sure your data is secure?

6/12/2019
How to Find a Software Development Company

You’ve identified the need for new software for your organization. You want it built and maintained but don’t have the knowledge, time, or ability to hire and manage a software staff. So how do you go about finding a software development company for your project? Step 1: Search for Existing Software The first step in […]

19/11/2019
3 Common Problems with Custom Software Development

Custom software is a great way to increase efficiency and revenue for your organization. However, creating custom software means more risk for you. Here are a few common problems to avoid when building your next mobile or web app. 1. Cost Overrun One of the biggest challenges of custom software development is gathering requirements. The process […]

3/11/2019
Staff Augmentation vs. Project-based Consulting

So, you want to build some software. But where do you start? Maybe you’re not ready to take on the large task of hiring a team internally. Of all the options out there for building your software, two of the most common are staff augmentation and project-based consulting. So what’s best for you, staff augmentation […]

28/10/2019
Agile Isn’t the Problem

Failed implementing agile in your organization? Agile isn't the problem.

10/9/2019
Should you hire software developers?

Are you ready to hire software developers? It might be worth more investigation.

29/8/2019
How long does a project take?

Breaking down how we work and what goes into each project.

19/8/2019
Observability of Systems

Solve your next production issue with less headache and better insight.

28/6/2019
Web vs Mobile: What’s Right for You?

How to use empathy to drive decisions around the platform for your future application.

17/6/2019
5 Tricks To Help Developers with Design

Developers tend to struggle with design, but there are a few quick changes that can make your software shine.

29/10/2018
Why should you use a G Suite Resller?

As of February 2018, Google had 4 million businesses using G Suite for email and file storage, collaborating on documents, video conferencing and more.