Logo Passei Direto
Buscar

UML0 27-Difference Between Cohesion and Coupling _ Baeldung on Computer Science

User badge image
Juke David

em

Material
páginas com resultados encontrados.
páginas com resultados encontrados.

Escolha uma das opções e acesse esse e outros materiais sem bloqueio. 🤩

Cadastre-se ou realize login

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

Escolha uma das opções e acesse esse e outros materiais sem bloqueio. 🤩

Cadastre-se ou realize login

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

Escolha uma das opções e acesse esse e outros materiais sem bloqueio. 🤩

Cadastre-se ou realize login

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

Escolha uma das opções e acesse esse e outros materiais sem bloqueio. 🤩

Cadastre-se ou realize login

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

Escolha uma das opções e acesse esse e outros materiais sem bloqueio. 🤩

Cadastre-se ou realize login

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

Escolha uma das opções e acesse esse e outros materiais sem bloqueio. 🤩

Cadastre-se ou realize login

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

Escolha uma das opções e acesse esse e outros materiais sem bloqueio. 🤩

Cadastre-se ou realize login

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

Escolha uma das opções e acesse esse e outros materiais sem bloqueio. 🤩

Cadastre-se ou realize login

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

Escolha uma das opções e acesse esse e outros materiais sem bloqueio. 🤩

Cadastre-se ou realize login

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

Escolha uma das opções e acesse esse e outros materiais sem bloqueio. 🤩

Cadastre-se ou realize login

Ao continuar, você aceita os Termos de Uso e Política de Privacidade

Prévia do material em texto

Difference Between Cohesion
and Coupling
Last updated: March 26, 2025
Written by: Ganesh Pagade
(https://www.baeldung.com/cs/author/ganesh-pagade)
Programming (https://www.baeldung.com/cs/category/core-
concepts/programming)
Design Patterns (https://www.baeldung.com/cs/tag/design-patterns)
Cohesion and coupling are common concepts in designing modular
software systems. Developed by Larry Constantine in the late 1960s
(https://en.wikipedia.org/wiki/Larry_Constantine#Structured_design), they
1. Introduction
 (/cs/) (/bael-search)
06/08/2026, 11:08 Difference Between Cohesion and Coupling | Baeldung on Computer Science
https://www.baeldung.com/cs/cohesion-vs-coupling 1/10
https://www.baeldung.com/cs/author/ganesh-pagade
https://www.baeldung.com/cs/author/ganesh-pagade
https://www.baeldung.com/cs/category/core-concepts/programming
https://www.baeldung.com/cs/tag/design-patterns
https://en.wikipedia.org/wiki/Larry_Constantine#Structured_design
https://en.wikipedia.org/wiki/Larry_Constantine#Structured_design
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/bael-search
have proved to be foundational in areas ranging from software design to
software metrics. They have subsequently become standard terms.
In this tutorial, we’ll study cohesion and coupling and how they correlate
with each other.
Cohesion is the degree to which the elements inside a module belong
together. A module could be a class or a package or even a microservice.
Simply put, it means “the code that changes together, stays together”.
A module with high cohesion contains elements that are tightly related to
each other and united in their purpose. For example, all the methods within
a User class should represent the user behavior.
A module is said to have low cohesion if it contains unrelated elements.
For example, a User class containing a method on how to validate the email
address. User class can be responsible for storing the email address of the
user but not for validating it or sending an email:
2. Cohesion
 (/cs/) (/bael-search)
06/08/2026, 11:08 Difference Between Cohesion and Coupling | Baeldung on Computer Science
https://www.baeldung.com/cs/cohesion-vs-coupling 2/10
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/bael-search
That should belong to some other class like Email.
As you can see, the concept of cohesion is closely related to the Single
Responsibility Principle (SRP, one of the SOLID principles (/solid-principles))
which states that a class should only have one responsibility. The module
following the SRP is likely to have high cohesion.
Modules with a single, well-defined purpose are easy to understand and
much more readable. The name of such modules clearly announces their
purpose and such modules do just that. It helps the reader to build an
intuition about what the module is doing without reading every line in the
module. Also, there are no surprises while reading the code of such
modules.
For example, it would be confusing to the reader if the User class contains
the code for validating the email address.
It is easier to make code changes since all the related code is within the
module. For example, if a developer has to make changes to the user
behavior, they can jump to the User class and make all the changes in one
class. This will keep the area of impact limited. Compare this to design
where user behavior is spread across multiple classes and each has to be
changed to achieve the desired change.
2.1. Advantages of High Cohesion
 (/cs/) (/bael-search)
06/08/2026, 11:08 Difference Between Cohesion and Coupling | Baeldung on Computer Science
https://www.baeldung.com/cs/cohesion-vs-coupling 3/10
https://www.baeldung.com/solid-principles
https://www.baeldung.com/solid-principles
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/bael-search
It is easier to test the code. Since such modules do not depend on other
modules for their purpose, they are easy to unit test. Also, it is easy to build
and deploy the changes when they are limited to a single module.
Changes to such modules are less prone to bugs. It is easier to make
mistakes when you are making changes across modules.
Finally, they are reusable. Since such modules perform single responsibility,
they tend to be used wherever there is such a need.
Overall, highly cohesive modules reflect better quality of software
design. Hence, look for elements in a module, that are not directly related to
the main purpose. Move them to some other module that better fits the
purpose or create a new module.
Coupling is the degree of interdependence between software modules. A
module could be a class or a package or even a microservice. Effectively,
the coupling is about how changing one thing required change in another.
3. Coupling
 (/cs/) (/bael-search)
06/08/2026, 11:08 Difference Between Cohesion and Coupling | Baeldung on Computer Science
https://www.baeldung.com/cs/cohesion-vs-coupling 4/10
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/bael-search
Two modules have high coupling (or tight coupling) if they are closely
connected. For example, two concrete classes storing references to each
other and calling each other’s methods. As shown in the diagram below,
Customer and Order are tightly coupled to each other. The Customer is
storing the list of all the orders placed by a customer, whereas the Order is
storing the reference to the Customer object.
Every time the customer places a new order, we need to add it to the order
list present inside the Customer. This seems an unnecessary dependency.
Also, Order only needs to know the customer identifier and does need a
reference to the Customer object. We could make the two classes loosely
coupled by making these changes:
 (/cs/) (/bael-search)
06/08/2026, 11:08 Difference Between Cohesion and Coupling | Baeldung on Computer Science
https://www.baeldung.com/cs/cohesion-vs-coupling 5/10
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/bael-search
Modules with low coupling among them work mostly independently of each
other.
Loosely coupled modules are easier to develop and maintain. Since they are
independent of each other, we can develop and test them in parallel. Also,
they can be modified and updated without affecting each other. We can
independently build and deploy such modules, significantly reducing the
deployment time.
Tightly coupled modules are difficult to change. The developer needs to
understand multiple modules and how they relate to each other. They needto be careful in making changes to all the modules consistently. This makes
it more error-prone. Also, we need to build, test and deploy each changed
module, further increasing the development effort.
Tightly coupled modules are also difficult to test. Unit testing a single
module is difficult since it heavily depends on other modules. Significant
effort has to be spent in mocking the calls to other modules so that the
module can be independently unit tested.
Integration tests are also difficult to set up. Overall the tests are fragile since
a change in any one module could break the tests. Debugging such
modules is also complex because it needs all the dependent modules
running.
A tightly coupled module is less likely to be reused. Such a module does not
perform anything useful on its own. Hence, it rarely fits the purpose for
someone else to reuse. Also pulling it as a dependency is difficult since it
3.1. Advantages of Low Coupling
 (/cs/) (/bael-search)
06/08/2026, 11:08 Difference Between Cohesion and Coupling | Baeldung on Computer Science
https://www.baeldung.com/cs/cohesion-vs-coupling 6/10
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/bael-search
brings in other dependent modules along with it.
Overall loose coupling reflects the higher quality of software design. Hence,
we should aim for designing modules that are as independent as possible.
Cohesion and coupling are related to each other. Each can affect the level
of the other.
High cohesion correlates with loose coupling. A module having its elements
tightly related to each other and serving a single purpose would sparingly
interact and depend on other modules. Thus, will have loose coupling with
other modules.
Similarly, the tight coupling could be a sign of low cohesion. Modules could
be heavily dependent on each other due to the elements spread across the
two modules. And thus, will have low cohesion.
Here is a quick comparison table between cohesion and coupling:
4. Cohesion vs. Coupling
 (/cs/) (/bael-search)
06/08/2026, 11:08 Difference Between Cohesion and Coupling | Baeldung on Computer Science
https://www.baeldung.com/cs/cohesion-vs-coupling 7/10
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/bael-search
In this tutorial, we studied cohesion and coupling and how they correlate
with each other.
5. Conclusion
 (/cs/) (/bael-search)
06/08/2026, 11:08 Difference Between Cohesion and Coupling | Baeldung on Computer Science
https://www.baeldung.com/cs/cohesion-vs-coupling 8/10
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/bael-search
CATEGORIES
ALGORITHMS (/CS/CATEGORY/ALGORITHMS)
ARTIFICIAL INTELLIGENCE (/CS/CATEGORY/AI)
CORE CONCEPTS (/CS/CATEGORY/CORE-CONCEPTS)
DATA STRUCTURES (/CS/CATEGORY/DATA-STRUCTURES)
LATEX (/CS/CATEGORY/LATEX)
NETWORKING (/CS/CATEGORY/NETWORKING)
SECURITY (/CS/CATEGORY/SECURITY)
SERIES
GRAPHS TUTORIAL (HTTPS://WWW.BAELDUNG.COM/CS/GRAPHS-SERIES)
NEURAL NETWORKS SERIES (HTTPS://WWW.BAELDUNG.COM/CS/NEURAL-NETWORKS-
SERIES)
LATEX SERIES (HTTPS://WWW.BAELDUNG.COM/CS/LATEX-SERIES)
ABOUT
ABOUT BAELDUNG (/ABOUT)
BAELDUNG ALL ACCESS (/COURSES)
THE FULL ARCHIVE (/CS/FULL_ARCHIVE)
EDITORS (/EDITORS)
OUR PARTNERS (/PARTNERS/)
PARTNER WITH BAELDUNG (/PARTNERS/WORK-WITH-US)
EBOOKS (/LIBRARY/)
FAQ (/LIBRARY/FAQ)
BAELDUNG PRO (/MEMBERS/)
TERMS OF SERVICE (/TERMS-OF-SERVICE)
PRIVACY POLICY (/PRIVACY-POLICY)
COMPANY INFO (/BAELDUNG-COMPANY-INFO)
CONTACT (/CONTACT)
PRIVACY MANAGER
 (/cs/) (/bael-search)
06/08/2026, 11:08 Difference Between Cohesion and Coupling | Baeldung on Computer Science
https://www.baeldung.com/cs/cohesion-vs-coupling 9/10
https://www.baeldung.com/cs/category/algorithms
https://www.baeldung.com/cs/category/algorithms
https://www.baeldung.com/cs/category/ai
https://www.baeldung.com/cs/category/ai
https://www.baeldung.com/cs/category/core-concepts
https://www.baeldung.com/cs/category/core-concepts
https://www.baeldung.com/cs/category/data-structures
https://www.baeldung.com/cs/category/data-structures
https://www.baeldung.com/cs/category/latex
https://www.baeldung.com/cs/category/latex
https://www.baeldung.com/cs/category/networking
https://www.baeldung.com/cs/category/networking
https://www.baeldung.com/cs/category/security
https://www.baeldung.com/cs/category/security
https://www.baeldung.com/cs/graphs-series
https://www.baeldung.com/cs/graphs-series
https://www.baeldung.com/cs/neural-networks-series
https://www.baeldung.com/cs/neural-networks-series
https://www.baeldung.com/cs/neural-networks-series
https://www.baeldung.com/cs/latex-series
https://www.baeldung.com/cs/latex-series
https://www.baeldung.com/about
https://www.baeldung.com/about
https://www.baeldung.com/courses
https://www.baeldung.com/courses
https://www.baeldung.com/cs/full_archive
https://www.baeldung.com/cs/full_archive
https://www.baeldung.com/editors
https://www.baeldung.com/editors
https://www.baeldung.com/partners/
https://www.baeldung.com/partners/
https://www.baeldung.com/partners/work-with-us
https://www.baeldung.com/partners/work-with-us
https://www.baeldung.com/library/
https://www.baeldung.com/library/
https://www.baeldung.com/library/faq
https://www.baeldung.com/library/faq
https://www.baeldung.com/members/
https://www.baeldung.com/members/
https://www.baeldung.com/terms-of-service
https://www.baeldung.com/terms-of-service
https://www.baeldung.com/privacy-policy
https://www.baeldung.com/privacy-policy
https://www.baeldung.com/baeldung-company-info
https://www.baeldung.com/baeldung-company-info
https://www.baeldung.com/contact
https://www.baeldung.com/contact
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/bael-search
 (/cs/) (/bael-search)
06/08/2026, 11:08 Difference Between Cohesion and Coupling | Baeldung on Computer Science
https://www.baeldung.com/cs/cohesion-vs-coupling 10/10
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/cs/
https://www.baeldung.com/bael-search