Cohesion

Cohesion refers to how strongly related and focused the functions within a module are.

Elaboration:

  • High cohesion โ†’ Module performs a single, well-defined task (preferred).
  • Low cohesion โ†’ Module performs multiple unrelated tasks (bad design).
  • Improves readability, maintainability, and reusability.

Example:

  • High Cohesion: A UserManager class handles user creation, authentication, and updates.
  • Low Cohesion: A UserManager class also handles file operations and logging (should be separate).