For example:
getBooks(author, title)
- If allowing author to be null, would return all books with specific title
- If allowing title to be null, would return all books for the specific author
- If allowing both to be null, would return all books regardless of title or author
To eliminate this, have the following functions:
getBooks(author)
getBooks(title)
getBooks(author, title)
getBooks()
In the new functions, there might be redundant codes or if we group those redundant codes into a function, we will still get into a function having null parameters. What’s a better way to handle this – no redundant code and no null parameters?
Don’t overload so much:
Note that this will not reduce code reuse: These methods could reuse/share whatever code they needed to in their implementations