In a well-designed C# assembly, code will be correctly grouped together. This is known as high cohesion. Low cohesion is when you have code grouped together that does not belong together.
You want related classes to be as independent as possible. The more dependent one class is on another class, the higher the coupling. This is known as tight coupling. The more independent classes are of one another, the lower the cohesion. This is known as low cohesion.
So, in a well-defined class, you want high cohesion and low coupling. We'll now look at examples of tight coupling followed by low coupling.
An example of tight coupling
In the following code example, the TightCouplingA class breaks encapsulation and makes the _name variable directly accessible. The _name variable should be private and modified only by the properties of methods within its enclosing class. The Name property provides get and set methods to validate the _name...