Monday, June 27, 2011

Cohesion and Coupling

■ Cohesion measures how closely aligned a module’s classes are with each other and with achieving the module’s intended functionality. You should strive for high cohesion in your modules. For example, a module shouldn’t address many different concerns (network communication, persistence, XML parsing, and soon): it should focus on a single concern.  In a nutshell, cohesion means single function.

■ Coupling, on the other hand, refers to how tightly bound or dependent different modules are on each other. You should strive for low coupling among your modules. For example, you don’t want every module to depend on all other modules.

No comments:

Post a Comment