sorry if that's a dumb title, i don't know how to express this clearly
say i have a logging trait:
trait Logging {
    def log(s:String)
}
and then some implementation
trait PrintlnLog extends Logging {
    def log(s:String) { println(s) }
}
which i use like this
class SomeProcess { this:Logging =>
   def doSomeJunk() {
      log("starting junk")
      ...
      log("junk finished")
   }
}
i could use this class like
val p = new SomeProcess () with PrintLog
p.doSomeJunk()
now what if i have this
class SubProcess { this:Logging => 
   def doSubJunk() {
      log("starting sub junk")
      ...
      log("finished sub junk")
   }
}
class ComplexProcess { this:Logging => 
   def doMoreJunk() {
       log("starting more junk")
       val s = new SubProcess with // ??? <-- help!
       s.doSubJunk()
       log("finished more junk")
   }
}
in ComplexProcess i want to instantiate a SubProcess mixing in the same logging trait that has been mixed into ComplexProcess, but ComplexProcess doesn't know what that is. is there a way to get a reference to it?
You cannot do that. In this case, you'd probably do something like this:
trait WithSubProcess {
  def s: SubProcess
}
class ComplexProcess { this: Logging with WithSubProcess ... }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With