Question about the pie template

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.

+3
source share
2 answers

There are two drawbacks to your approach:

  • Contextgets too much responsibility by mixing methods from UserRepository, UserServiceetc .;
  • - , UserRepository a lazy val, , UserService (, , );

, ( var s).

+5

, , // / .

, , "" , - , , , , .

, - (tm), .

+2

All Articles