Class Coupling1 min read

What is class coupling?

Class coupling is a measure of class complexity and it’s subclasses. It is showing us how deep are classes interconnected.

We have two types of coupling:

  1. Tight coupling
  2. Loosely coupling

1.Tight coupling

Tight coupling is when one class is dependent on the other class and each class change triggers rebuilding of other (dependent) class.

2. Loosely coupling

This type of coupling is ideal and makes perfect software. Why? Because when we change one class we dont want to change half of the application or we don’t want to rebuild whole application beacuse of one class change.
How do we build loosely coupled apps? We build them by:

  • Encapsulation
  • Interfaces
  • Class relationships ( inheritance or composition )

When creating relationships between classes we use inheritance and/or composition.
Preffered way of building relationships is by using composition.

Leave a Reply

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