Scala traits exposing protected members? -


given class like:

class myclass {     protected object myobj { ... } } 

is possible write trait permit exposing myobj. e.g. inheritance following:

class testmyclass extends myclass {     val getmyobj = myobj } 

but want via trait, following doesn't typecheck:

trait exposemyobj {     val getmyobj = myobj        // super.myobj/this.myobj don't work  } 

and use like:

class testmyclass extends exposemyobj 

is possible reproduce functionality in testmyclass trait expose protected object, , if how?

if know trait mixed in instance of myclass (or subclass), can enforce expectation self-type, , access object:

trait exposemyobj {     self: myclass =>      val getmyobj = myobj } 

edit: example of using trait:

class testmyclass extends myclass exposemyobj  val test = new testmyclass test.getmyobj // accesses myobj defined in myclass. 

edit 2: attempting address @jbrown's comment (re: testing queries within repos) - @ doing following - first, in each repo's file, add trait each repo holding queries repo:

trait userqueries { // @ making protected, if    protected def query1(param: string) = list(param) // silly implementation, enough make point   ... // other queries }  class userrepo extends userqueries // has (internal) access queries 

then in test class file given repo:

class userqueriestester extends userqueries scalatest { // or whatever test framework using    // (public) tests run - eg:   def testquery1 = query1("test") should (list("test"))  } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -