Friday, July 29, 2016

APIs should be impossible to misuse

It should hard or impossible to misuse a good API
Josh Block
https://www.youtube.com/watch?v=aAb7hSCtvGw

The above statement validates my preference for using the Builder Pattern to facilitate clients to provide named constructor arguments in a sense. E.g. if a constructor has several string parameters, rather than rely on flaky javadocs and parameter names to inform the user what to provide, I would prefer to provide builder methods that unambiguously let the user know what to provide. For validation of inputs, I make the null checks, etc, in the private constructor. That makes it about as hard to misuse the API/constructor as possible in Java.

No comments:

Post a Comment