Imagine a game that needs to score words. A words needs to be scored immediately, in a list of words or even in a list of words from list of players.
I've created a scoring module which has the following public methods:
score_single_word(word) -> int
score_list_of_words(list) -> int
score_group_of_players(players) -> [int]
These methods obviously cascade, so score_group_of_players
does some calculation and calls score_list_of_words
eventually calls score_single_word
.
Unfortunately, the every method requires clean up, such that the words are lowercase, stripped of white space and unique. Otherwise their respectives task would fail. I didn't see another way but doing that clean up multiple times, since neither method can be sure its assumptions are fulfilled earlier by one of the higher methods.
What can I do to remove those unnecessary clean ups while making sure that the assumptions are still correct?