You are on page 1of 8

Cohesion and Coupling

Saiden Xavier Andrew A. Pascual


Gerald Tolentino
Cohesion
What is Cohesion?

• It refers to the degree to which the elements of a module belong together.


Thus, cohesion measures the strength of relationship between pieces of
functionality within a given module. In other words, cohesion means grouping
together code that contributes to a single task.

- This is apply to object oriented programming. Each object should only have
one responsibility. Every behavior of that object should only do one task. Any more
than that and you'll have a much harder time making changes to the code.
Cohesion
- this is an ordinal type of measurement is usually describe as:
High Cohesion Low Cohesion
- Tend to preferable, because high cohesion is - This is associated with several undesirable
associated with several desirable traits of traits such as being difficult to maintain, test,
software including robustness, reliability, reuse, or even understand.
reusability, and understandability.
- This would then lead to the code that is not
Advantages: easy to change and error prone.
• Reduced module complexity (they are simpler, having fewer
operations).
• Increased system maintainability, because logical changes in the
domain affect fewer modules, and because changes in one module
require fewer changes in other modules.
• Increased module reusability, because application developers will
find the component they need more easily among the cohesive set
of operations provided by the module.
Types of Cohesion
• Coincidental cohesion- is when parts of a module are • Communicational cohesion- is when parts of a module are
grouped arbitrarily; the only relationship between the parts is that grouped because they operate on the same data.
they have been grouped together.
(Example: A module which operates on the same record of
(Example: Utilities) information).
• Logical cohesion- is when parts of a module are grouped • Sequential cohesion- is when parts of a module are grouped
because they are logically categorized to do the same thing even because the output from one part is the input to another part like
though they are different by nature an assembly line.
(Example: Grouping all mouse and keyboard input handling (Example: A function which reads data from a file and
routines). processes the data).
• Temporal cohesion- is when parts of a module are grouped by • Functional cohesion- is when parts of a module are grouped
when they are processed - the parts are processed data particular because they all contribute to a single well-defined task of the
time in program execution. module.
(Example: A function which is called after catching an (Example: Lexical analysis of an XML string).
exception which closes open files, creates an error log,
and notifies the user).
• Procedural cohesion- is when parts of a module are grouped
because they always follow a certain sequence of execution.
(Example: A function which checks file permissions and then
opens the file).
Cohesion
• Cohesion is the principle of grouping like code together and ensure
each function performs only a single task. Cohesion helps to create
code that is maintainable and reusable.
Coupling
What is Coupling?
• This is the manner and degree of interdependence between software
modules. A measure of how closely connected two routines or
modules are the strength of the relationships between modules.

You might also like