Skip to content

Instantly share code, notes, and snippets.

@djspiewak
Created October 17, 2012 22:26
Show Gist options
  • Save djspiewak/3908729 to your computer and use it in GitHub Desktop.
Save djspiewak/3908729 to your computer and use it in GitHub Desktop.
trait ConfigComponent {
type Config
def config: Config
}
trait MySQLStorageComponent extends StorageComponent with ConfigComponent {
type Config <: MySQLConfig
override def storeUser(user: User) { ... }
override def retrieveUser(id: Int): Option[User] = ...
case class User(id: Int, hash:Vector[Byte]) extends UserLike
trait MySQLConfig {
def mysqlHost: String
def mysqlPort: Int
}
}
trait GravatarComponent extends StorageComponent {
type Config <: GravatarConfig
def avatarURL(user: User): String = { ... }
trait GravatarConfig {
def token: String
}
}
class RESTService extends MySQLStorageComponent with GravatarComponent with ... {
type Config = config.type
override object config extends MySQLConfig with GravatarConfig {
val mysqlHost = "localhost
val mysqlPort = 3336
val token = "1234cafebabe"
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment