Home  >  Article  >  Backend Development  >  Cohesion in C#

Cohesion in C#

王林
王林forward
2023-09-10 18:25:021035browse

C# 中的内聚性

Cohesion in C# shows the relationship between modules. It shows the functional strength of the module. The higher the cohesion, the better the program design.

It is a dependency between elements inside a module (such as methods and internal modules). High cohesion will allow you to reuse classes and methods.

An example of high cohesion can be seen in the System.Math class, i.e. it has mathematical constants and static methods -

Math.Abs
Math.PI
Math.Pow

Classes that do many things at the same time are difficult to understand and maintain. This is what we call low cohesion and should be avoided. If a class will provide email, printing, copying, etc. functionality, it will be difficult to maintain and reuse.

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

The above is the detailed content of Cohesion in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete