Let's make a contract: the art of designing a Java API
summary
Concrete rules for Java APIs: prefer static factory methods and small value objects (example: replace three confusing buy overloads with a Price object and fluent builder) so signatures stay consistent; use the loan pattern (e.g. withFile(Consumer<InputStream>)) so the API controls closing resources and prevents leaks; expose the weakest useful type (Iterable/Collection not ArrayList), return empty collections not null, and avoid throwing checked IOExceptions from APIs unnecessarily; split monster interfaces (hundreds of methods) into responsibility-focused subinterfaces; avoid boolean flags, use enums.
AI-written summary · about
chapters (17)
- 0:00Red Hat
- 3:01What is an API? ?
- 3:26And why should I care?
- 4:16Understandable Basic Principles
- 7:46If in doubt, leave it out
- 10:32Write meaningful Javadocs
- 12:17Convenience methods
- 16:26Promote fluent API
- 20:24Use the weakest possible type also for returned value
- 22:23Support lambdas
- 24:11Avoid checked exceptions
- 26:58Stay in control (loan pattern)
- 31:26Break apart large interfaces into smaller versions
- 33:22Be defensive with your data
- 36:17Prefer enums to boolean parameters
- 38:09Use meaningful return types
- 46:49API design is an iterative process
related talks
51mLet's make a contract: the art of designing a Java API
27mModern Java API Design
52m10 Reasons Why we Love Some APIs and Why we Hate Some Others
44mMastering Resilient Java API Design: From Principles to Practice
34mDesigning a Compatible API — Genius Without Villainy
40mFuture-Proofing Java: The Art of Crafting Resilient APIs
15mHow to Design Effective APIs | Actionable Guide
50mThe Good, the Bad and the Ugly of Java API Design
