Created
April 21, 2014 07:38
-
-
Save ghik/11135240 to your computer and use it in GitHub Desktop.
Stackable traits example
This file contains hidden or 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
| 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