Cohesion in C#

CsharpProgrammingServer Side Programming

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 i.e.it has Mathematical constants and static methods −

Math.Abs
Math.PI
Math.Pow

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.

raja
Published on 17-Sep-2018 12:04:06
Advertisements