In: Computer Science
Which cohesion does this method belong to?
Public void sampleMethod(int flag)
{
Switch (flag) {
Case ON:
// code
Case OFF:
// code
Case CLOSE:
//code
}
}
Cohesion
Cohesion is a design technique and it is a part of system design. It is the measure of the functional strength of a module.
High cohesion is preferred because it reduces the error propagation, increases the reusability of a module, and decreases the complexity of the design.
If we have changed the parent class then we need to make a lot of changes in the subclass as well. It means that cohesion is low but cohesion must be high.
Type of cohesion:
Here, we have given a function that performs a well-defined task. An integer type parameter is passed and on the basis of the passed parameter, a specific action is performed.
So, the given source code is an example of a functional cohesion.
Functional cohesion is best because it reduces the error propagation chances.