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

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

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -