Please consider the following implementation of the Decorator design pattern:
WordBank objects store strings and return them to the client through the method
The decorator class,
WordSorter, is a subclass of
WordBank (as in the Decorator pattern). However it's implementation of
getWords() sorts some of the strings and removes them, before returning the array to the client.
For example a
WordSorter might delete all of the strings in the bank that start with letter 'a', and only after that return the array to the client.
Does this violate the Liskov Substitution Principle? Since some implementations of
WordBank return strings while others first sort through the strings and only return some of them, I'm not sure if it's safe to say that a
WordSorter can be used anywhere any other
WordBank is used. Or am I understanding this principle wrong?