scala - Replacing delegation with cake -


at moment i'm stacking features on class delegation

trait backend {   def product(id: int): string }  class mybackend extends backend {   def product(id: int) = "my product" }  class loggingbackend(underlying: backend) extends backend {   override def product(id: int) = {     println(s"get product $id")     underlying.product(id)   } }  class cachingbackend(underlying: backend) extends backend { /* ... */ } 

is possible replace code this?

trait logging {   : backend =>    def product(id: int) = {     println(s"get product $id")     /* don't know write here */   } }  class myloggingbackend extends mybackend logging 

you need change logging:

trait logging extends backend {   abstract override def product(id: int) = {     println(s"get product $id")     super.product(id)   } } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -