Last active
August 29, 2015 14:03
-
-
Save tstone/cc229419898ddea0394d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo(x: Int) { | |
def this(x: String) = this(x.toInt) | |
} | |
class Bar(x: Int) | |
object Bar { | |
def apply(x: String) = new Bar(x.toInt) | |
} | |
// in use... | |
val f = new Foo("15") | |
val b = Bar("15") | |
// --------------------------------------------------------- | |
// Approach #1 | |
class RedisCache(client: RedisClient, keyPrefix: Option[String] = None) { | |
def this(host: String, port: Int, keyPrefix: Option[String] = None)(implicit system: ActorSystem) = | |
this(new RedisClient(host, port)(system), keyPrefix) | |
} | |
val r = new RedisCache("http://redis.example.com", 100) with AppLogger | |
// Approach #2 | |
class RedisCache(client: RedisClient, keyPrefix: Option[String]) | |
object RedisCache { | |
def apply(host: String, port: Int, log: LoggerLike, keyPrefix: Option[String] = None) = | |
new RedisCache(new RedisClient(host, port), keyPrefix) { | |
val logger = log | |
} | |
} | |
val r = RedisCache("http://redis.example.com", 100, AppLogger.logger) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment