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 loose coupling?

For that, you need to understand isolation by using Encapsulation. The relationship 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 code to reuse.
  3. Polymorphic behavior
  4. Composition:- Is a kind of relationship between 2 classes that allows one object to contain into another object. Is Has-a relationship.

Ex. The bike has an Engine

Sagar Jaybhay, from Maharashtra, India, is currently a Senior Software Developer at Software Company. He has continuously grown in the roles that he has held in the more than seven years he has been with this company. Sagar Jaybhay is an excellent team member and prides himself on his work contributions to his team and company as a whole.

Sagar Jaybhay

Sagar Jaybhay, from Maharashtra, India, is currently a Senior Software Developer at Software Company. He has continuously grown in the roles that he has held in the more than seven years he has been with this company. Sagar Jaybhay is an excellent team member and prides himself on his work contributions to his team and company as a whole.

You may also like...