Created
June 15, 2011 22:56
-
-
Save kings13y/1028332 to your computer and use it in GitHub Desktop.
Self reference types
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
trait DB { def startDB: Unit } // defines an abstract start for a DB component | |
trait MT { def startMT: Unit } // defines an abstract start for an MT component | |
trait Oracle extends DB { def startDB = println("Starting Oracle") } // Some actual concrete instances.. dummied for example | |
trait Service extends MT { def startMT = println("Starting Service") } | |
trait App { | |
self: DB with MT => // declare that self for App refers to a DB with MT, so that we have access to the startXX ops | |
startDB | |
startMT | |
} | |
object DummyApp extends App with Oracle with Service // create a concrete instance with an actual DB and MT instance | |
DummyApp.run // run it and see "Starting Oracle" then "Starting Service" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment