GR

Groovy Architecture Patterns

Modular and idiomatic architecture patterns for Groovy applications

Details

Language / Topic
groovyGroovy
Category
Architecture

Rules

balanced
- Use Groovy traits for horizontal reuse of behavior across unrelated class hierarchies — prefer traits over mixins for their explicit contract.
- Apply the builder pattern with a Groovy DSL closure (`build { option 'value' }`) to construct complex configuration objects readably.
- Use `@Delegate` to compose behaviors from multiple collaborators instead of deep inheritance hierarchies.
- Structure Grails applications with the standard layer convention: controllers for HTTP, services for business logic, and GORM domain classes for persistence.
- Use Groovy's `@Builder` AST transformation to generate fluent builder APIs for configuration and domain objects without boilerplate.
- Use `@Singleton` pattern with Groovy's built-in `@groovy.lang.Singleton` for true singleton enforcement rather than manual double-checked locking.
- Define application-wide DSLs using `ConfigSlurper` or custom `Script` subclasses to give configuration files a type-safe, IDE-friendly syntax.