We will always find middle man in between producer and consumer of anything. Sometimes more than one layer of middle man. Both producer and end user hate those middle man. They just rip profit by somehow involving in transaction. But no one will deny it require lots of thinking to establish a model which doesn't need middle man. Let’s understand what kind of value these middle men bring.
Like real world every software or services is integration of various modules. Each module is responsible to carry out certain task. Some component consumes the output of other; to integrate these we need middle man. In Java we say it “Interface”. The basic idea of interface is to act like middle man. But in Java world it can do some additional things.
1) As the name suggest Interface is basically to integrate two different components. It exposes the functionality of one component to other in a simple manner.
2) It can be used to hold Constants of the project. As the properties of Interface are always public and final.
3) Java doesn’t allow multiple inheritance. So One class can’t extend multiple classes, the work around in Interface. One class can implement multiple interfaces. And a reference of an Interface can hold the Object of implementing class.
Class A implements Ia {}
Ia ia = new A();
In this way it gives lots of option to designer.
4) Interface enforces certain behavior on the class. For ex: if my object is instance of Serializable, then the object can be persisted. Interface is used to mark the Object.
5) I found the best use of interface is it helps to design lots of generic stuffs. It helps in reducing tight coupling between component.
Please share your thoughts and experience with Interface in programming and real life as well.