A good software design implies clean decomposition of the problem into modules and the neat arrangement of these modules in a hierarchy. The primary characteristics of neat module decomposition are low coupling and high cohesion.
Cohesion is a measure of functional strength of a module. A module having low coupling and high cohesion is said to be functionally independent of other modules. Functional independence means that a cohesive module performs a single function or task. A functionally independent module has very little interaction with other modules.
Types of Cohesion
The different classes of cohesion that a module may possess are shown in Fig. 4.1.
- Coincidental Cohesion: A module is said to have coincidental cohesion if it performs a set of function or tasks that relate to each other very loosely. In this case, the module contains a random collection of functions. It is likely that the functions have been put in the module out of pure coincidence without any design or thought. For example, in a transaction processing system (TPS), the get-input, print-error, and summarize members functions are grouped into one module. The grouping does not have any relevance to the structure of the problem.
- Logical Cohesion: A module is said to be logically cohesive, if all elements of the module perform similar operations, e.g. error handling, data input, data output, etc. An example of logical cohesion is the case where a set of print functions generating different output reports are arranged into a single module.
- Temporal Cohesion: When a module contains functions that are related by the fact that all the functions must be executed in the same time span, the module is said to exhibit temporal cohesion. The set of functions responsible for initialization, start-up, a shutdown of some process, etc. exhibit temporal cohesion.
- Procedural Cohesion: A module is said to possess procedural cohesion, if the set of functions of the module are all part of a procedure (algorithm) in which certain sequence of steps have to be carried out for achieving an objective, e.g. the algorithm for decoding a message.
- Communicational Cohesion: A module is said to have communicational cohesion, if all functions of the module refer to or update the same data structure, e.g. the set of functions defined on an array or a stack.
- Sequential Cohesion: A module is said to possess sequential cohesion if the elements of a module form the parts of the sequence, where the output from one element of the sequence is input to the next. For example, in a TPS, the get-input, validate-input, sort-input functions are grouped into one module.
- Functional Cohesion: Functional cohesion is said to exist if different elements of a module cooperate to achieve a single function. For example, a module containing all the functions required to manage employees’ pay-roll exhibits functional cohesion. Suppose a module shows functional cohesion and we are asked to tell what the module does, then we would be able to tell it using a single sentence.
Coupling between two modules is a measure of the degree of interaction or interdependence between the two modules. A module having low coupling and high cohesion is said to be functionally independent of other modules.
If two modules interchange huge amounts of data/information, then they are highly interdependent. The degree of coupling between two modules depends on their interface complexity, which is basically determined by the number of types of parameters that are interchanged while invoking the functions of the module.
Types of Coupling
The classification of the different types of coupling helps to quantitatively estimate the degree of coupling between two modules. Five types of coupling can occur between any two modules. This is shown in Fig. 4.2.
- Data Coupling: Two modules are data coupled if they communicate through a parameter. An example is an elementary data item passed as a parameter between two modules, e.g. an integer, a float, a character, etc. This data item should be problem-related and not used for the control purpose.
- Stamp Coupling: Two modules are stamp coupled if they communicate using a composite data item such as a record in PASCAL or a structure in C.
- Control Coupling: Control coupling exists between two modules if data from one module is used to direct the order of instructions executed in another. An example of control coupling is a flag set in one module and tested in another module.
- Common Coupling: Two modules are common coupled if they share data through some global data items.
- Content Coupling: Content coupling exists between two modules if they share code, e.g. a branch from one module into another module.
Read Further: Wikipedia
- Software Development Life Cycle – All Models
- Requirements Elicitation
- Software Requirement Specification
- Analysis Modeling
- Software Design