Advertisement
Guest User

Untitled

a guest
Dec 29th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. case class User(name: String)
  2.  
  3. trait UserRepositoryComponent {
  4. val userRepository: UserRepository
  5. class UserRepository {
  6. def authenticate(username: String, password: String): User = {
  7. println("authenticating user: " + username)
  8. User(username)
  9. }
  10. def create(user: User) = println("creating user: " + user)
  11. def delete(user: User) = println("deleting user: " + user)
  12. }
  13. }
  14.  
  15. trait UserServiceComponent { this: UserRepositoryComponent =>
  16. val userService: UserService
  17. class UserService {
  18. def authenticate(username: String, password: String): User = userRepository.authenticate(username, password)
  19. def create(username: String) = userRepository.create(new User(username))
  20. def delete(user: User) = userRepository.delete(user)
  21. }
  22. }
  23.  
  24. object ComponentRegistry extends UserServiceComponent with UserRepositoryComponent {
  25. val userRepository = new UserRepository
  26. val userService = new UserService
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement