Class Coupling

Tight Coupling- Suppose we have 2 classes A and B and other class C, D, E are tightly coupled with A and B. In this if we change some code in A, B then dependent classes needs to be changed and so on. So that’s why in real time we have to avoid or try to minimize tight coupling.

Loose Coupling: – In here when we change the change should be isolated we don’t want to change dependent classes of application.

How to achieve loosecoupling?

For that, you need tounderstand isolation by using Encapsulation. Therelationship between classes and most important Interface. It is an Is-a relationship

Ex. In Mobile service center front desk people not supposed to tell how to repair the mobile phone. This is the responsibility of that repairer.

In C# there are 2 types of relationship

  1. Inheritance – more of tight coupling
  2. Composition – Composition relationship results in loose coupling.
  1. Inheritance:-Depict parent-child relationship
  2.  is used for the codeto reuse.
  3. Polymorphic behavior
  4. Composition:- Is a kind of relationship between2 classes that allows one object to containinto another object. Is Has-arelationship.

Ex. The bikehas an Engine

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *