Coupling and Cohesion in Software Engineering
Coupling and Cohesion in Software Engineering
Engineering
Introduction: The purpose of the Design phase in the Software Development
Life Cycle is to produce a solution to a problem given in the SRS (Software
Requirement Specification) document. The output of the design phase is a
Software Design Document (SDD).
Coupling and Cohesion are two key concepts in software engineering that are
used to measure the quality of a software system’s design.
Coupling refers to the degree of interdependence between software modules.
High coupling means that modules are closely connected and changes in one
module may affect other modules. Low coupling means that modules are
independent and changes in one module have little impact on other modules.
Cohesion refers to the degree to which elements within a module work together
to fulfill a single, well-defined purpose. High cohesion means that elements are
closely related and focused on a single purpose, while low cohesion means that
elements are loosely related and serve multiple purposes.
Both coupling and cohesion are important factors in determining the
maintainability, scalability, and reliability of a software system. High coupling
and low cohesion can make a system difficult to change and test, while low
coupling and high cohesion make a system easier to maintain and improve.
The module simply means the software components that are been created by
dividing the software. The software is divided into various components that work
together to form a single functioning item but sometimes they can perform as a
complete function if not connected with each other. This process of creating
software modules is known as Modularity in software engineering. It simply
measures the degree to which these components are made up than can be
combined. Some of the projects or software designs are very complex that it’s
not easy to understand its working and functioning. In such cases, modularity is
a key weapon that helps in reducing the complexity of such software or
projects. The basic principle of Modularity is that “Systems should be built from
cohesive, loosely coupled components (modules)” which means s system
should be made up of different components that are united and work together in
an efficient way and such components have a well-defined function. To define a
modular system, several properties or criteria are there under which we can
evaluate a design method while considering its abilities. These criteria are
defined by Meyer. Some of them are given below:
1. Modular Decomposability – Decomposability simply means to break down
something into smaller pieces. Modular decomposability means to break
down the problem into different sub-problems in a systematic manner.
Solving a large problem is difficult sometimes, so the decomposition helps in
reducing the complexity of the problem, and sub-problems created can be
solved independently. This helps in achieving the basic principle of
modularity.
2. Modular Composability – Composability simply means the ability to
combine modules that are created. It’s actually the principle of system
design that deals with the way in which two or more components are related
or connected to each other. Modular composability means to assemble the
modules into a new system that means to connect the combine the
components into a new system.
3. Modular Understandability – Understandability simply means the capability
of being understood, quality of comprehensible. Modular understandability
means to make it easier for the user to understand each module so that it is
very easy to develop software and change it as per requirement. Sometimes
it’s not easy to understand the process models because of its complexity and
its large size in structure. Using modularity understandability, it becomes
easier to understand the problem in an efficient way without any issue.
4. Modular Continuity – Continuity simply means unbroken or consistent or
uninterrupted connection for a long period of time without any change or
being stopped. Modular continuity means making changes to the system
requirements that will cause changes in the modules individually without
causing any effect or change in the overall system or software.
5. Modular Protection – Protection simply means to keep something safe from
any harms, to protect against any unpleasant means or damage. Modular
protection means to keep safe the other modules from the abnormal
condition occurring in a particular module at run time. The abnormal
condition can be an error or failure also known as run-time errors. The side
effects of these errors are constrained within the module.
Example to understand modularity better:
In the object-oriented approach, the concept of modularity revolves around the
concept of well-organized interactions between different components.
Modularity refers to an organizing structure in which different components of a
software system are divided into separate functional units.
For example, a house or apartment can be viewed as consisting of several
interacting units; electrical, heating, cooling, plumbing, structure, etc. Rather
than viewing it as one giant jumble of wires, vents, pipes, and boards, the
organized architect designing a house or apartment will view them as separate
modules that interact in well-defined ways. In doing so, he/she is using the
concept of modularity to bring clarity of thought that provides a natural way of
organizing functions into distinct manageable units. Likewise, using modularity
in a software system can also provide a powerful organizing framework that
brings clarity to an implementation.
Cohesion refers to the degree to which the elements within a module are related
to each other and contribute to a single objective.
High coupling increases the risk of side effects and makes it harder to modify or
replace individual modules without affecting the entire system’s functionality.
It involves encapsulating the internal details of a module and exposing only the
necessary interfaces for other modules to interact with it.
It also allows for better testing and debugging, as modules can be treated as
black boxes, focusing solely on their inputs, outputs, and expected behavior.
This improves the overall readability of the code, enabling developers to grasp its
logic and architecture quickly.
This reduces the need for coordination and minimizes conflicts that may arise
when multiple developers are working on the same codebase.
The modular structure of software systems facilitates the debugging and testing
processes.
When a bug or issue arises, developers can isolate the problematic module and
focus solely on that part of the code.
This narrow scope makes it easier to identify the root cause and apply targeted
fixes.
Additionally, modular code is easier to test since each module can be tested
independently, verifying its inputs, outputs, and expected behavior.
This increases the reliability of the software and reduces the time spent on
debugging and testing.
Developers must prioritize modules that provide the most value and gradually
introduce modularity into the system while ensuring backward compatibility and
maintaining functionality.
Pure functions are deterministic and do not have side effects, making them highly
modular and easy to reason about.
By composing functions, developers can build complex systems by combining
simpler, self-contained components.
Conclusion
Modularity in software engineering is a fundamental concept that offers
numerous benefits.
Learn all of the essential skills and hands-on experience crucial for success in
software engineering through the Institute of Data’s Software Engineering
program.
Coupling defines the interdependence of modules, while cohesion measures the unity
of components. Achieving low coupling and high cohesion promotes maintainable and
comprehensible modular structures. This symbiotic relationship allows developers to
navigate complexity that improves testing, scalability, and teamwork. These principles
permeate the entire software lifecycle and impact project management and customer
satisfaction.
Connection and cohesion lead to solutions that are not only functional but also
elegant, adaptable and innovative.
What is Coupling?
Coupling refers to the degree of interdependence between different modules, classes,
or components of a software system. It shows how closely these elements relate to
each other and how much one element depends on the behavior, data or interfaces of
another. High coupling means strong interconnections where changes in one module
can cascade through others, while low coupling means greater independence and
isolation between modules.
Type of Coupling:
1. Content Coupling:
Modules share data directly through global variables or parameters. This is the
strongest coupling method and is not recommended because it tightly couples
the modules and makes them highly dependent on each other.
2. General Coupling:
Modules share global data or resources that are frequently used and modified by
different modules. Although not as direct as pooling content, it still represents
tight pooling through shared resources.
3. External Coupling:
Modules communicate by exchanging data through external interfaces such as
function parameters or method calls. Although external binding is more flexible
than content and general binding, it can still cause dependencies.
4. Control Coupling:
One module affects the behavior of another by passing control information, often
through parameters. This type of connection may be less direct than a content
connection but still requires close communication.
5. Stamp Coupling:
Modules share a composite data structure such as a record or object without
sharing. Changes to the structure can affect several modules, but the connection
is weaker than in the content connection.
6. Data Coupling:
Modules share data through parameters, but there is no direct relationship
between functions. Compared to the previous types, it is a relatively loose form of
connection.
7. No Coupling:
Modules work independently without direct communication. This is the ideal type
of connection to aim for as it encourages modular design and minimizes the
impact of changes.
What is Cohesion?
Cohesion in software engineering refers to the degree of interrelatedness and focus
among the elements within a module, class, or component. It measures how well the
internal components of a module work together to achieve a single, well-defined
purpose. High cohesion indicates that the elements within a module are closely related
and contribute collectively to a specific functionality. Low cohesion suggests that the
elements are less focused and may serve multiple unrelated purposes.
Types of Cohesion:
1. Functional Cohesion:
Elements within a module are grouped based on a single, specific functionality or
task. This is the strongest form of cohesion, where all elements contribute to the
same goal.
2. Sequential Cohesion:
Elements are organized in a linear sequence, where the output of one element
becomes the input of the next. This type of cohesion is often seen in processes
with step-by-step execution.
3. Communicational Cohesion:
Elements within a module work together to manipulate a shared data structure.
They might not perform the same function, but their actions are closely related to
a common piece of data.
4. Procedural Cohesion:
Elements are grouped based on their involvement in a specific sequence of
actions or steps. They might share some data, but their primary focus is on the
sequence of operations.
5. Temporal Cohesion:
Elements are grouped because they need to be executed at the same time or
during the same phase. They might not share functional or data-related aspects.
6. Coincidental Cohesion:
Elements are grouped arbitrarily without a clear, meaningful relationship. This
type of cohesion is typically indicative of poor module design.
Coupling and cohesion significantly shape developer collaboration. Low coupling and
high cohesion lead to clear module responsibilities, enabling effective communication,
parallel development, isolated changes, and streamlined code review. Debugging is
easier, and new team members onboard swiftly. These principles minimize conflicts,
fostering efficient teamwork, smoother coordination, and higher-quality software
development.
Information Hiding:
Encapsulation:
Modularity
Information Hiding:
Modularity
In the 1972 paper, Parnas cites his goal as modularity (as evident from
the title of the paper). But what are the benefits of modularity?
However, for the last point to be valid, your modules should possess
certain positive traits. In Bartosz Milewski’s online series ‘Category
Theory for Programmers’, he posits that modules are useful when the
information required to compose them grows slower than the
information required to implement them. “The idea is that, once a
chunk is implemented, we can forget about the details of its
implementation and concentrate on how it interacts with other chunks.”
This is also what good encapsulation can help you achieve.
I’m sure I’ve missed out quite a few upsides (and potential downsides)
of modularity. However, I hope the discussion has helped better
understand the intertwined relationships between modularity,
encapsulation and information hiding.
Delegation: Principles and Types
Delegation is the process of assigning authority, responsibility, and tasks to
individuals or teams within an organization. It involves transferring decision-
making authority from managers to their subordinates, empowering them to
make decisions and take action within their assigned roles. By delegating tasks,
managers can focus on higher-level responsibilities and strategic decision-
making while their subordinates handle operational or specialized tasks.
Delegation includes elements, such as authority, responsibility, accountability,
and effective communication. It brings several benefits, including increased
productivity, skill development, empowerment, improved decision-making, and
succession planning. Effective delegation requires considering factors, like
employee competence, workload capacity, and task complexity, along with
providing adequate support and feedback for successful task completion.
Principles of Delegation
To make delegation of authority effective, managers need to follow certain
principles. These are some principles of delegation;