API Design Golden Rule
Michael Feathers highlights that designing APIs is a challenging task, particularly when they are intended for a large audience. The designer must consider how the API can be modified in the future without breaking existing client code, and how users may affect the internal implementation of the API. To address these concerns, some API developers lock down the API by making most of their classes and methods final, sealed, or presented through a singleton or static factory methods. However, this approach may not be sufficient, as it can hinder the ability of developers to write unit tests for their code that uses the API.
Feathers argues that to address this testing issue, API designers must follow the Golden Rule of API Design. This rule suggests that developers should not only write tests for the API they develop but also write unit tests for code that uses their API. By doing so, designers can experience firsthand the testing hurdles that their users may encounter and design the API accordingly. While constructs like static, final, and sealed can be useful at times, it is important to be aware of the testing issue and approach it as any other design challenge. #APIDesignChallenge