Effective java encourages use to interfaces rather than abstract / concrete classes. Question is if there is an interface heirachy, which interface type should be chosen and why ?
For example, an ArrayList
implements List
which implements Collection
which implements a Iterable
.
So when do we pass a list
vs collection
vs iterable
?
Obvious answer is that each subclasses keep adding more functions. So should we keep climb up the hierarchy until the required functionality is matched ?
I mean if in an imaginary application only iterator()
is needed then use Iterable
else use List
?