Created
April 6, 2014 19:23
-
-
Save Dierk/10010410 to your computer and use it in GitHub Desktop.
Using modular traits in Groovy 2.3.0-beta-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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