Types of Cohesion in Software Engineering


In software engineering, cohesion refers to the degree to which the elements (functions, methods, or modules) within a software module or component are related to each other. High cohesion indicates that the elements are closely related and focused on a single, well-defined purpose, while low cohesion suggests that the elements are loosely related or have multiple unrelated purposes within the module. There are several types or levels of cohesion, each with its own characteristics and implications. Here are some common types of cohesion:

  1. Functional Cohesion:

    • Functional cohesion is the highest level of cohesion and represents the most desirable state.
    • In functionally cohesive modules, all elements are related by a common function or purpose.
    • The module performs a single, well-defined task or function, and all elements within it support that task.
    • Changes to the module typically require modifications to multiple elements to maintain its single purpose.
  2. Sequential Cohesion:

    • In modules with sequential cohesion, elements are related because they are executed in a specific, linear order.
    • Each element relies on the output of the previous one, and there is a strict flow of control.
    • This type of cohesion is common in procedures or methods that perform a series of steps.
  3. Communicational Cohesion:

    • Communicational cohesion occurs when elements within a module are grouped together because they share common data or need to communicate with each other.
    • Elements within the module operate within a common data context.
    • Changes to the shared data or data-sharing mechanisms may impact multiple elements within the module.
  4. Procedural Cohesion:

    • Procedural cohesion involves elements that are grouped together because they are related by the execution of a specific procedure or task.
    • While they may not share the same data context, they are still related by their role in a larger procedure.
  5. Temporal Cohesion:

    • Temporal cohesion occurs when elements are grouped together because they are executed at the same time or during the same phase of a program.
    • This type of cohesion can lead to modules that perform multiple unrelated tasks within a single phase.
  6. Logical Cohesion:

    • Logical cohesion is a weaker form of cohesion where elements are grouped together based on some logical relationship, but this relationship may not always be obvious.
    • It is generally considered less desirable than functional cohesion.
  7. Coincidental Cohesion:

    • Coincidental cohesion is the lowest level of cohesion and represents a module where elements have no meaningful relationship with each other.
    • Elements are combined merely by coincidence, often due to historical reasons or poor design.

When designing and developing software, the goal is to achieve the highest level of cohesion possible within modules while minimizing coupling, which is the degree of interdependence between modules. High cohesion and low coupling promote modularity, maintainability, and ease of understanding and testing in software systems. Designing modules with functional cohesion, where all elements share a common purpose, is typically the preferred goal. However, the choice of cohesion type may depend on the specific requirements and nature of the problem being solved.

Post a Comment

Previous Post Next Post