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 TopLevelComponent extends | |
BlogRepoComponent with | |
PostRepoComponent with | |
AuthRepoComponent with | |
BlogServComponent with | |
PostServComponent with | |
AuthServComponent |
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
abstract class Application extends TopLevelComponent { | |
// can access blogRepo, postRepo, authRepo, blogServ, postServ, | |
// and authServ here | |
} |
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 TopLevelComponentImpl extends TopLevelComponent with | |
BlogRepoComponentImpl with | |
PostRepoComponentImpl with | |
AuthRepoComponentImpl with | |
BlogServComponentImpl with | |
PostServComponentImpl with | |
AuthServComponentImpl |
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
new Application with TopLevelComponentImpl |
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 AuthRepo { | |
def create(auth: Author): AuthId | |
def retrieve(id: AuthId): Author | |
def update(auth: Author): Unit | |
def delete(auth: Author): Unit | |
} | |
class AuthRepoImpl extends AuthRepo { | |
def create(auth: Author) = println(s"create $auth") | |
def retrieve(id: AuthId) = { |
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 AuthRepoComponent { | |
val authRepo: AuthRepo | |
} | |
trait AuthRepoComponentImpl extends AuthRepoComponent { | |
val authRepo: AuthRepo = new AuthRepoImpl | |
} | |
trait AuthServComponent { | |
val authServ: AuthServ |
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 TopLevelComponent { | |
val blogRepo: BlogRepo | |
val postRepo: PostRepo | |
val authRepo: AuthRepo | |
val blogServ: BlogServ | |
val postServ: PostServ | |
val authServ: AuthServ | |
} | |
trait TopLevelComponentImpl extends TopLevelComponent { |
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 AuthServComponent { | |
val authServ: AuthServ | |
} | |
trait AuthServComponentImpl extends AuthServComponent { | |
self: AuthRepoComponent => // this is the self-type | |
val authServ: AuthServ = new AuthServ(authRepo) | |
} |
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 AServiceComponent { | |
self: BServiceComponent => | |
val aService = new AService | |
class AService { | |
println(s"hi from $this constructor, b is $bService") | |
def greet: Unit = | |
println(s"hi from $this greet, b is $bService") | |
} | |
} |
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 TopComponent extends AServiceComponent with BServiceComponent | |
object Application extends App with TopComponent { | |
aService.greet | |
bService.greet | |
} |