~/talk

Let's make a contract: the art of designing a Java API

Talkat Voxxed Days Ticino 2021 · on Thursday, 2021-11-18· [api-design, java]
slides:none on file

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

  1. 0:00Red Hat
  2. 3:01What is an API? ?
  3. 3:26And why should I care?
  4. 4:16Understandable Basic Principles
  5. 7:46If in doubt, leave it out
  6. 10:32Write meaningful Javadocs
  7. 12:17Convenience methods
  8. 16:26Promote fluent API
  9. 20:24Use the weakest possible type also for returned value
  10. 22:23Support lambdas
  11. 24:11Avoid checked exceptions
  12. 26:58Stay in control (loan pattern)
  13. 31:26Break apart large interfaces into smaller versions
  14. 33:22Be defensive with your data
  15. 36:17Prefer enums to boolean parameters
  16. 38:09Use meaningful return types
  17. 46:49API design is an iterative process
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.