I just read Jonas' well-known article about Cake Pattern, for a class like:
class UserRepository {
def authenticate(user: User): User = {
println("authenticating user: " + user)
user
}
def create(user: User) = println("creating user: " + user)
def delete(user: User) = println("deleting user: " + user)
}
According to that article, for using Cake Pattern, it need to be wrapped as inner class in a trait, e.g.:
trait UserRepositoryComponent {
val userRepository: UserRepository
class UserRepository {
...
}
}
So I am wondering:
- Is this the only way to achieve Cake Pattern?
- If so, does it mean class such as
UserRepository
has to be designed with Cake Pattern in mind at the time it's designed (so that they can be wrapped in a trait)? - If the answer is yes, is there any common practice that can include a class that is not defined within a wrapper into a design based on Cake Pattern? (something similar to adapter in concept)