Sunday, August 18, 2019

Cohesion and Coupling


Coupling - A measure of how much a module (package, class, method) relies on other modules. It is desirable to reduce coupling, or reduce the amount that a given module relies on the other modules of a system.


Cohesion - A measure of how closely related the members (classes, methods, functionality within a method) of a module are to the other members of the same module. It is desirable to increase cohesion as that indicates that a module has a very specific task and does only that task.


Cohesion is the indication of the relationship within module.
Coupling is the indication of the relationships between modules.

Cohesion shows the module’s relative functional strength.
Coupling shows the relative independence among the modules.

Cohesion is a degree (quality) to which a component / module focuses on the single thing.
Coupling is a degree to which a component / module is connected to the other modules.

While designing you should strive for high cohesion i.e. a cohesive component/ module focus on a single task (i.e., single-mindedness) with little interaction with other modules of the system.
While designing you should strive for low coupling i.e. dependency between modules should be less.

Cohesion is the kind of natural extension of data hiding for example, class having all members visible with a package having default visibility.
Making private fields, private methods and non public classes provides loose coupling.

Cohesion is Intra – Module Concept.
Coupling is Inter -Module Concept.



Cohesion describe a structure inside a module.
Coupling describe a relationship between multi modules.

No comments:

Followers

Link