Rethinking API Design with Traits
summary
Groovy 2.3 adds a new trait feature that provides stateful and composable behavior bricks usable on JDK 6/7/8; traits compile to an interface plus a helper class and are compatible with static compilation. Traits resolve method conflicts by declaration order or explicit super calls, and use namespaced trait fields so a class and its traits don’t clash — it avoids diamond problem. Runtime coercion of objects to traits generates a proxy (so runtime coercion creates proxy and incurs allocation cost).
AI-written summary · about
chapters (20)
- 0:00Intro
- 0:27About me
- 1:45About Groovy
- 12:15Delegation
- 14:30Groovy example
- 16:45Extension methods
- 20:22Default methods
- 23:21Stateless methods
- 25:35Groovy
- 26:35Flying
- 28:47Basic Traits
- 30:46State
- 32:34Multiple Trades
- 33:47Trades as Capabilities
- 34:46Traits as Inheritance
- 37:33External vs Implements
- 39:20Abstract Methods
- 41:54Why Traits
- 47:49Traits Matter
- 55:35Runtime coercion
related talks
40mFuture-Proofing Java: The Art of Crafting Resilient APIs
27mModern Java API Design
44mMastering Resilient Java API Design: From Principles to Practice
25mEverything is an API
34mDesigning a Compatible API — Genius Without Villainy
39mAPI Design as an Art
49mThe Good, the Bad and the Ugly of Java API design
41mDesigning A Great Ruby API
