The Cake Pattern
article suggests using traits as namespaces:
trait UserRepositoryComponent {
val userRepository: UserRepository
class UserRepository {...}
}
trait UserServiceComponent {this: UserRepositoryComponent =>
val userService: UserService
class UserService {...}
}
class Context extends UserServiceComponent with UserRepositoryComponent {
val userRepository = new UserRepository
val userService = new UserService
}
However do we really need these "namespace traits" (UserServiceComponent
and UserRepositoryComponent
) if we can do the following ?
trait UserRepository {...}
trait UserService {this: UserRepository =>
...
}
class Context extends UserRepositoryImpl with UserService
So, my question is when and why we need the "namespace" trait in the Cake Pattern
.