Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 0.70 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Bidirectional Links in Traits with Different Types
  2. val parentOrder = new ParentOrder
  3. val childOrder = new ChildOrder
  4.  
  5. childOrder.addParent(parentOrder)
  6.        
  7. trait PolyTree[T <: PolyTree[T, C], C <: PolyTree[T, C]]  { self: T =>
  8.  
  9.  
  10.     private val _parents: ListBuffer[T] = ListBuffer()
  11.     private val _children: ListBuffer[C] = ListBuffer()
  12.  
  13.     def addParent(parent: T): PolyTree[T, C] = {
  14.  
  15.         _parents += parent
  16.  
  17.         parent._children += this // Error
  18.  
  19.  
  20.         this
  21.     }
  22.  
  23.  
  24.     def addChild(child: C): PolyTree[T, C] = {
  25.  
  26.         _children += child
  27.  
  28.         child._parents += this        
  29.  
  30.         this
  31.  
  32.     }
  33.  
  34.  
  35.  
  36.  
  37. }
  38.        
  39. trait PolyTree[T <: PolyTree[T, C], C <: PolyTree[T, C]]  { self: T with C => ...