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
Post a Comment