title: scala: reuse subclass implementation as a subclass of two different classes?
body: <p>To simplify my actual code let's say there are two classes, one a subclass of the other:</p>
  
  <pre><code>class Chair {
     val canFold = false;
     // ...
  }
  
  class FoldableChair extends Chair {
     val canFold = true;
     // ...
  } 
  </code></pre>
  
  <p>and in my implementation I will have potentially hundreds of other subclasses of Chair or FoldableChair:</p>
  
  <pre><code>class Armchair extends ... {}
  class DeckChair extends ... {} 
  //... etc
  </code></pre>
  
  <p>For each of these subclasses, suppose each one has a lengthy implementation but I want to be able to have it sometimes extend Chair and sometimes extend FoldableChair - without duplicating the code. I'd like to do so without having the subclass itself be extended. Is this possible somehow? Do I need to use traits to do this?</p>
  
  <p>I'd also like to be able to create particular instances of a subclass which sometimes extend Chair and sometimes extend FoldableChair, but that choice is made when instantiating it. Is this possible too? Thanks!</p>
  
  <p>Edit: to clarify, what I really want is this:</p>
  
  <pre><code>class Armchair extends Chair {}
  
  class ArmchairFoldable extends FoldableChair {}
  </code></pre>
  
  <p>but the implementation of Armchair and ArmchairFoldable are exactly the same. That is, I'd like to not duplicate their implementations.</p>