Skip to content

Instantly share code, notes, and snippets.

@josephpconley
Created July 18, 2014 15:34
Show Gist options
  • Save josephpconley/812bceda27772cb30cfc to your computer and use it in GitHub Desktop.
Save josephpconley/812bceda27772cb30cfc to your computer and use it in GitHub Desktop.
/**
* User: jconley
* Date: 7/14/2014
*/
trait Db {
def name: String
}
class MySQLDb extends Db {
val name = "MySQL"
}
class PostgresDb extends Db {
val name = "Postgres"
}
trait WeatherWS {
def currentTemp: Double
}
class ForecastIOWeatherWS extends WeatherWS {
def currentTemp = 101.5
}
class WeatherDotComWeatherWS extends WeatherWS {
def currentTemp = 99.7
}
trait DbConfig {
val db: Db
}
trait WeatherWSConfig {
val weather: WeatherWS
}
trait GlobalConfig extends DbConfig with WeatherWSConfig {
def ping = println(s"Db is ${db.name} Weather is ${weather.currentTemp}")
}
object Parfait extends App {
val config = new GlobalConfig{
val db = new PostgresDb
val weather = new WeatherDotComWeatherWS
}
config.ping
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment