mixins

Mixing behavior into Groovy classes at runtime.

Groovy Traits Tutorial – Reusable Behavior Composition with 10+ Examples

Learn Groovy traits for reusable behavior composition with 10+ tested examples. Trait methods, fields, interfaces, conflicts, and runtime traits on Groovy 5.x. “Favor composition over inheritance. Traits give you the best of both worlds – you compose behavior like interfaces but with real implementation.” Guillaume Laforge, Groovy Project Lead Last Updated: March 2026 | Tested on: Groovy 5.x, Java 17+ | Difficulty: Intermediate | Reading Time: 18 minutes Sharing behavior across classes that don’t share a common ancestor is painful ... Read More

Groovy Categories and Mixins – Extend Existing Classes with 10+ Examples

Learn Groovy categories and mixins with 10+ tested examples. Add scoped methods to classes, compose behaviors, and extend JDK classes safely. “Categories let you try on new methods like clothes – wear them when you need them, take them off when you’re done.” Dave Thomas, The Pragmatic Programmer Last Updated: March 2026 | Tested on: Groovy 5.x, Java 17+ | Difficulty: Intermediate | Reading Time: 18 minutes Adding methods globally with ExpandoMetaClass is powerful but permanent (until cleanup). What if ... Read More