DEV Community

Discussion on: Do you really understand interfaces?

Collapse
 
rossdrew profile image
Ross • Edited

Your teacher was bad. That's the problem here. An interface is a contract, that is all. This multiple inheritance answer is the type of thing a bedded in C++ dev would answer to why Java has interfaces.

Interfaces are a contract that I will adhere to so that:

a. I can substitute the implementation for another without changing the class which uses it. Therefore we can wire programs together with -for example- DI or Tests.

b. Third parties know the contract and can write functionality for it

Collapse
 
gaurang847 profile image
Gaurang

Omg. That is so to-the-point. I love it!
I hope though that if my teacher is reading this, she doesn't realise she's being called out on. Might hurt her 🙊