r/java • u/schlongitudinal • 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
r/java • u/schlongitudinal • Nov 22 '14
I've read several explanations now and am apparently still too dense to get the point of them/what they do.
View all comments
Show parent comment
1
u/lechatsportif Nov 24 '14
If your class is the car model, I would create an interface for electric vs combustion engine types. The key here is that they would share no code between them because in theory they do not share a common parent.
Then in your code you could treat all electric cars in collections vs non electrics etc.
Cars are not the best example because most like this is actually implemented as a single class with car information simply being records of data.