Coupling and Interfaces :

Mathanraj TMathanraj T
2 min read

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 :)

2
Subscribe to my newsletter

Read articles from Mathanraj T directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mathanraj T
Mathanraj T

I am a student who is keen on learning and exploring new things and excited about entering the world of developers where I can find the best way to learn new technology, tools and keep updated. Excited to learn by doing. Always open to learning and feedback.