scala - Overriding a trait and selftype -


i want override scalatest trait beforeandaftereach have stuff implemented once tests. got compile, don't understand why.

trait mysetup extends beforeandaftereach {   : org.scalatest.beforeandaftereach org.scalatest.suite =>   var service: string = _    abstract override def beforeeach(): unit = {     service = "apa"     super.beforeeach()   }    abstract override def aftereach(): unit = {     service = ""   } } 

the thing got working line:

  : org.scalatest.beforeandaftereach org.scalatest.suite => 

i found in beginning of beforeandaftereach implementation , copied it.

what do, , why need it?

update:

this simpler version.

trait mysetup extends flatspec beforeandaftereach {   var service: string = _    override def beforeeach {     service = "apa"     super.beforeeach   }    override def aftereach {     service = ""     super.aftereach   } } 

beforeandaftereach has self-type of suite, meaning beforeandaftereach can mixed in type extends suite. scalatest wants pick primary suite type first , mix-in behavior afterwards.

the self-type declaration not inherited in sub-traits have redeclare self-type.

the following question has tradeoffs between self-types , sub-traits: what difference between self-types , trait subclasses?

for background on scalatest design, see: http://www.artima.com/scalazine/articles/selfless_trait_pattern.html


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -