Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using modular traits in Groovy 2.3.0-beta-1
trait HasId {
long id
}
trait HasVersion {
long version
}
trait Persistent {
boolean save() { println "saving ${this.dump()}" }
}
trait Entity implements Persistent, HasId, HasVersion {
boolean save() {
version++
Persistent.super.save()
}
}
class Publication implements Entity {
String title
}
class Book extends Publication {
String isbn
}
Entity gina = new Book(id:1, version:1, title:"gina", isbn:"111111")
gina.save()
assert gina.version == 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.