Coupling and Interfaces :

The article will give a real world understanding of coupling and interfaces.

In simple words,

Coupling : How two object get connected tightly or loosely

Interface : The part of portion of object that help them to connect.

Most of us use computer, laptop which come with a memory unit called RAM. There are two types of RAM based on how it get attached to the Device.

There are

  • Dedicated RAM : where we can change the RAM through the slot in the mother board.

  • Integrated RAM : Where the RAM get Fixed to the mother board.

Now we are going to connect the above concept with Coupling and interface in OOPS. Here RAM slot represent interface. RAM represent class. If we observe the above comparison closely we can say that the device with integrated RAM don't allow us to change RAM (class) which result in tightly coupling. If we go for Dedicated RAM we can change RAM ( class ) which result in loosely coupling.

for demonstration. I am using an animal class you can use what ever class you want

Instead of concrete implementation like

Animal cow = new Animal();

We use interface to make it loosely coupled.

IAnimal cow = new Animal();

An interface in OOPs is contract or action the class implementing should provide.

Hope, I make the you to understand the concept. To better understand the interface. Follow my next Blog :)