(This is a hypothetical question for discussion, I have no actual problem).
Say that I'm making an implementation of SortedSet
by extending LinkedHashMap
:
class LinkedHashSortedMapThing extends LinkedHashMap implements SortedSet {
...
}
Now programmers who use this class may do
LinkedHashMap x = new LinkedHashSortedMapThing();
But what if I consider the extending of LinkedHashMap
an implementation detail, and do not want it to be a part of the class' contract? If people use the line above, I can no longer freely change this detail without worrying about breaking existing code.
Is there any way to prevent this sort of thing, other than favouring composition over inheritance (which is not always possible due to private/protected members)?