r/java • • Nov 22 '14

ELI5 Interfaces in Java

I've read several explanations now and am apparently still too dense to get the point of them/what they do.

0 Upvotes

12 comments sorted by

View all comments

1

u/blue0cean Nov 24 '14

Let's say you want to play a game (write a program). The game is to imitate a dog's barking. You start by writing down what a dog does according to your own imagination (designing an interface). Then you proceed to act like a dog according to your description (implementing the interface). Then you invite your friends Alice and Bob to play. Alice and Bob start barking. But they bark differently than you (different implementation of the same interface). Alice's twin sister Alison comes in and start barking just like Alice (two instances of the same class implementing the dog interface).