Skip to content

Instantly share code, notes, and snippets.

@ghik
Created April 21, 2014 07:38
Show Gist options
  • Select an option

  • Save ghik/11135240 to your computer and use it in GitHub Desktop.

Select an option

Save ghik/11135240 to your computer and use it in GitHub Desktop.
Stackable traits example
class Base {
def work() {
// do some work
}
}
trait Logging extends Base {
override def work() {
log("Doing work")
super.work()
log("Work done")
}
}
trait EventPublishing extends Base {
override def work() {
super.work()
publishEvent(new WorkDoneEvent)
}
}
class Concrete extends Base with EventPublishing with Logging
// Concrete.work() = Logging.work() where super.work() is EventPublishing.work() where super.work is Base.work()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment