Sobes.tech
Middle

What is the difference between adhesion and cohesion?

sobes.tech AI

Answer from AI

Coupling and Cohesion are two key metrics in software design that determine the quality of modules.

  • Coupling describes how closely connected different modules of a program are. Low coupling is preferable because it means modules are independent and changes in one module have less impact on others.

    Examples:

    • High coupling: Module A directly accesses the internal data of Module B or calls its private methods.
    • Low coupling: Modules interact through well-defined interfaces or messages.
  • Cohesion describes how closely related the elements within a single module are. High cohesion is preferable because it means the elements of a module serve a single function or purpose.

    Examples:

    • Low cohesion: A module contains a set of loosely related functions performing different tasks.
    • High cohesion: A module contains functions and data that collectively perform a specific task (e.g., a module for database operations, payment processing).

Ideally, a system should have low coupling between modules and high cohesion within each module. This leads to more flexible, maintainable, and scalable code.