daily pastebin goal
54%
SHARE
TWEET

Untitled

a guest Dec 29th, 2016 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top