People use the interface to hide the details of implementation details. For example, I want to write a function that returns the size of a collection — it could be a list, an array, a map, whatever, I don’t care. I will use pseudo code, this does not apply to Java:
int length (Collection c) { return c.size(); }
Otherwise, I have to implement 'map_length, list_length' and dozens of other methods. And it will blow your code a lot.
Another common example is databases. There are quite a lot of them with various APIs, language queries, performance, etc. I do not know in advance which one they prefer to use in your application. This way you can create a common database interface and use it as a placeholder around your code. Although you hide the exact databases behind the interface, you can switch between different databases without any problems.
I would recommend you read further on inheritance and patterns.
source share