Skip to content

Instantly share code, notes, and snippets.

@sbrady
Created January 15, 2015 05:57
Show Gist options
  • Save sbrady/277dd678509061e35bf5 to your computer and use it in GitHub Desktop.
Save sbrady/277dd678509061e35bf5 to your computer and use it in GitHub Desktop.
Example decorator pattern in Groovy using @DeleGate
class Person {
String firstName
String lastName
}
class PersonDecorator {
private @Delegate Person person
def fullName() {
"$firstName $lastName"
}
}
def person = new Person(firstName: "Sean", lastName: "Brady")
def personDecorator = new PersonDecorator(person: person)
println personDecorator.fullName()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment