Cohesion in C#

Cohesion in C# shows the relationship within modules. It shows the functional strength of the modules. The greater the cohesion, the better will be the program design.

It is the dependency between the modules internal elements like methods and internal modules. High cohesion will allow you to reuse classes and method.

An example of High cohesion can be seen in System.Math class has Mathematical constants and static methods −


A class that does a lot of things at a time is hard to understand and maintain. This is what we call low cohesion and should be avoided. If a class will provide functions for email, print, copy, etc time, then it would be hard to maintain and reuse.

Always try to achieve strong i.e. high cohesion in your code.

Samual Sam
Samual Sam

Learning faster. Every day.