You extend the interface when the subinterface provides everything that the superinterface provides, and does something else important. For example, SortedMap<K,V>
implements Map<K,V>
, because a sorted map is a map that supports all display operations, as well as some operations that apply only to sorted maps.
This is similar to inheritance between classes, but allows for many implementations. For example, you can implement SortedMap
as a sorted list of keys plus a parallel array of values, rather than a tree. This will allow users to perform faster or more efficient implementations without changing the rest of the code. In other words, inheritance between interfaces allows you to preserve the benefits of programming for interfaces.
source share