EDIT is a scala mailing list question which I thought is duplicated here. My answer is related to providing three different constructors (i.e. For replicating a Java design) and not a class extension
Assuming each of your constructors ultimately creates a state S object, create a companion object with static methods to create this state
object Base { private def stateFrom(d : Double) : S = error("TODO") private def stateFrom(s : Str) : S = error("TODO") private def stateFrom(i : Int) : S = error("TODO") }
Then create a private constructor that takes state and (public) overloaded constructors that port to the primary constructor
import Base._ class Base private(s : S) {
oxbow_lakes Jul 21 '10 at 2:00 p.m. 2010-07-21 14:00
source share