title: Using overloaded constructors from the superclass
body: <p>I'm writing a message parser. Suppose I have a superclass <code>Message</code> with two auxiliary constructors, one that accepts <code>String</code> raw messages and one that accepts a <code>Map</code> with datafields mapped out in key-value pairs.</p>
  
  <pre><code>class Message {
    def this(s: String)
    def this(m: Map[String, String])
  
    def toRaw = { ... } # call third party lib to return the generated msg
    def map # call third party lib to return the parsed message
  
    def something1 # something common for all messages which would be overriden in child classes
    def something2 # something common for all messages which would be overriden in child classes
    ...
  }
  </code></pre>
  
  <p>There's good reason to do this as the library that does parsing/generating is kind of awkward and removing the complexity of interfacing with it into a separate class makes sense, the child class would look something like this:</p>
  
  <pre><code>class SomeMessage extends Message {
    def something1 # ...
    def something2 # ...
  }
  </code></pre>
  
  <p>and the idea is to use the overloaded constructors in the child class, for example:</p>
  
  <pre><code>val msg = new SomeMessage(rawMessage) # or
  val msg = new SomeMessage("fld1" -&gt; ".....", "fld2" -&gt; "....")
  
  # and then be able to call
  msg.something1
  msg.something2 # ...
  </code></pre>
  
  <p>However, the way auxiliary constructors and inheritance seem to behave in Scala this pattern has proven to be pretty challenging, and the simplest solution I found so far is to create a method called <code>constructMe</code>, which does the work of the constructors in the above case:</p>
  
  <pre><code>val msg = new SomeMessage
  msg.constructMe(rawMessage) # or
  msg.constructMe("fld1" -&gt; ".....", "fld2" -&gt; "....")
  </code></pre>
  
  <p>which seems crazy to need a method called <code>constructMe</code>.</p>
  
  <p><strong>So, the question:</strong></p>
  
  <p>is there a way to structure the code so to simply use the overloaded constructors from the superclass? For example:</p>
  
  <pre><code>val msg = new SomeMessage(rawMessage) # or
  val msg = new SomeMessage("fld1" -&gt; ".....", "fld2" -&gt; "....")
  </code></pre>
  
  <p>or am I simply approaching the problem the wrong way?</p>