In my web application authorized user has at least 4 "facets": http session related data, persistent data, facebook data, runtime business data.
I've decided to go with case class composition instead of traits for at least two reasons:
- traits mixing can cause name clashes
- i want the free case class goodies like pattern matching and copy method
I'd like to know experienced scalaists opinions on this subject. It looks like traits and/or cake pattern should be suitable for such tasks but as i've mentioned above there are problems... Its obvious that not only i want to implement it fast and easy but also to understand it in depth for using in future.
So does my decision have any flaws and misunderstanding or is it right? Related code looks like this:
case class FacebookUserInfo(name: String, friends: List[Long])
case class HttpUserInfo(sessionId: String, lastInteractionTime: Long, reconnect: Boolean)
case class RuntimeQuizUserInfo(recentScore: Int)
trait UserState {
def db: User
def http: HttpUserInfo
}
case class ConnectingUser(db: User, http: HttpUserInfo) extends UserState
case class DisconnectedUser(db: User, http: HttpUserInfo, facebook: Option[FacebookUserInfo]) extends UserState
case class AuthorizedUser(db: User, http: HttpUserInfo, facebook: FacebookUserInfo,
quiz: RuntimeQuizUserInfo) extends UserState