Core concept
class DB private (url: String)
object DB {
def apply(url: String): DB = new DB(url) // controlled
}Advertisement
How it works
More flexible than direct constructor. Validation, caching.
Advertisement
Trade-offs + gotchas
Anywhere construction needs control.