Make development easier with obvious APIs enforced at compile time Temporal coupling is a serious code smell. It should be for a developer to call a good API incorrectly. hard Usage of a BadApi that is temporally coupled The above code compiled, yet an error was thrown are runtime. Why? BadApi implementation The field was not set calling . Requiring certain methods of a class to be called in a specific order is known as , which slows down development velocity. badApi.url before login() temporal coupling How to avoid temporal coupling Usage of a good api Other than passing invalid data, it is difficult to call this API incorrectly. GoodApi implementation Bonus points Validate early, with type-safe objects instead of . Strings Two possibile implementations: .login() fun login(username: String, password: String) fun login(username: Username, password: Password) #1 allows the developer to accidentally mix-up the username and password fields (code compiles because both parameters are Strings), while #2 makes that impossible. Code is available on . GitHub Catch the conversation on ! Reddit Part 2: API Design — Handling Exceptions
Share Your Thoughts