Here his recipes to write good APIs:
- An API must provide sufficient functionality for the caller to achieve its task. Here, the author emphasizes to make sure that nothing is missing.
- An API should be minimal, without imposing undue inconvenience on the caller. (well, that's not easy unfortunately :-(
- APIs cannot be designed without an understanding of their context. In the other word, the API designer needs to imagine some use cases: if there's something unexpected, do we need to throw an exception ? or just return null ?
- General purpose APIs should be policy free, "special purpose" APIs should "policy rich". The author suggests that if the context is unknown (case of general purpose), we can use the strategy pattern.
- APIs should be designed from the perspective of the caller. This is clear, but not easy though.
- Good APIs don't pass the buck. Don't add extra parameters if we are not sure !
- APIs should be documented before they are implemented. We have to be more disciplined.