Question: I have a normal tree defined in Scala.

```
sealed abstract class Tree
object Tree {
  case class Node (...) extends Tree
  case class Leaf (...) extends Tree
}

```

Now I want to add a member variable to all nodes and leaves in the tree.
Is it possible with extend keyword or do I have to modify the tree classes by adding [T]?

**Update:**  

It seems that my question was misunderstood.
Example should clear it up:

I need this Tree structure (actually something more complicated) have two Doubles in one context.
In another context I need it to have one string. And yet in another context I need pure tree without any (additional) members. And I would like first two variants to *be* the third variant.
Pseudocode:

```
DTree extends Tree with Touple2[Double, Double]
object DTree {
  case class Node (...) extends Tree.Node with Touple2[Double, Double]
  case class Leaf (...) extends Tree.Leaf with Touple2[Double, Double]
}

STree extends Tree with String
object DTree {
  case class Node (...) extends Tree.Node with String
  case class Leaf (...) extends Tree.Leaf with String
}

...

def f (t : Tree) { ... }

```

I want f to be able to handle all the trees.

Answer: 
If I understand you correctly, you want some of your tree nodes to have a type with a field of that type. I think an [abstract type](http://www.scala-lang.org/node/105) is what you're looking for. They're like generics, but better suited to sub-classing. Something like this.

```
sealed abstract class Tree

trait TypedTree {
  type T
  val value:T
}

```

Then which, when I modify your example, results in:

```
trait DTree extends TypedTree {
  type T = Touple2[Double, Double]
}
object DTree {
  case class Node (...) extends Tree.Node with DTree 
  case class Leaf (...) extends Tree.Leaf with DTree 
}

trait STree extends TypedTree {
  type T = String
}
object DTree {
  case class Node (...) extends Tree.Node with STree
  case class Leaf (...) extends Tree.Leaf with STree
}

```

This adds a level of indirection. But I get the feeling that you're conceptualizing something in one step where two are necessary.
Abstract classes may have constructors (traits may not), so you can just put the common elements in the `abstract class Tree`:

```
abstract
class Tree(te1: String, te2: Int)

case
class Node(...)
extends Tree(te1Arg, te2Arg)

```

and so on. Note that you have to supply the base class constructor parameters in the `extends` clause of the subclass definition.