Temporal cohesion is one of the levels of cohesion in software engineering that describes how elements within a module are related based on the timing or temporal sequence of their execution. In other words, elements with temporal cohesion are grouped together because they are executed at the same time or during the same phase of a program's execution. Here are key characteristics and considerations related to temporal cohesion:
Same Phase of Execution: Elements with temporal cohesion are executed together during the same phase or stage of a program's execution. This means that they are typically related to a specific part of the program's operation.
Limited Logical Relationship: While there is a temporal relationship between the elements, they may not have a strong or obvious logical relationship in terms of their function or purpose.
Sequential Execution: Temporal cohesion often involves a sequential execution of elements, where one element's execution depends on the completion of the previous one.
Common Timing: Elements within a module with temporal cohesion may share a common timing requirement, such as being executed at program startup, shutdown, or during a specific event.
Use Cases: Temporal cohesion can be suitable for certain tasks where elements need to be executed together in a specific sequence. For example, initialization routines in a program may exhibit temporal cohesion as they are executed during program startup.
Testing Considerations: Testing elements with temporal cohesion may involve verifying that they execute correctly in the specified sequence and timing. Dependencies between these elements should be considered during testing.
Potential for Confusion: If not well-structured, modules with temporal cohesion can become hard to understand and maintain, especially as the number of elements and their interactions increase.
Refactoring Opportunity: In some cases, it may be beneficial to refactor a module with temporal cohesion to improve its organization and clarity. Consider whether the elements can be grouped more logically based on their functionality.
Balancing Cohesion Types: While temporal cohesion may be appropriate for certain elements within a program, it is generally desirable to aim for higher levels of cohesion, such as functional cohesion, within modules to promote modularity and maintainability.
In summary, temporal cohesion in software engineering describes modules or components where elements are related because they are executed together during the same phase or at the same time within a program's execution. While this form of cohesion is suitable for specific tasks, care should be taken to ensure that the module remains well-structured, organized, and maintainable as the program evolves.