The article Cake Pattern 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 properties” ( UserServiceComponentand 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 do we need a “namespace property” in Cake Pattern.
source
share