This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Wouldn't it be nifty if this worked?

1 reply
Aaron 2
Joined: 2011-10-21,
User offline. Last seen 42 years 45 weeks ago.

I understand why it doesn't, but wouldn't it be super cool if it did?
Is there another way of accomplishing the same thing?

trait Dave { def foo : String }

class Delegate(underlying : Dave) extends Dave {
import underlying._
// delegate now implements all of Dave's methods, delegating to the
underlying impl
}

Sciss
Joined: 2008-12-17,
User offline. Last seen 28 weeks 5 days ago.
Re: Wouldn't it be nifty if this worked?

you can do this with the autoproxy compiler plugin, i believe:

https://github.com/kevinwright/Autoproxy-Lite

i think this is really a common design pattern, so i hope something comes out of this project:

https://github.com/TiarkRompf/scala-virtualized

which notes as a key feature: "transparent proxies: re-route all method calls on these proxy objects to a forwarder method".

(-offtopic- i'm personally hoping for a removal of the "new" keyword, so that you could do something like

trait Graph {
def funkyStuff : Int
}

object DSL {
def graph( body: @new[ Graph ]) : Graph = ???
}

import DSL._

graph { funkyStuff + 33 }
)

best, -sciss-

On 21 Oct 2011, at 08:52, Aaron wrote:

> I understand why it doesn't, but wouldn't it be super cool if it did?
> Is there another way of accomplishing the same thing?
>
>
> trait Dave { def foo : String }
>
> class Delegate(underlying : Dave) extends Dave {
> import underlying._
> // delegate now implements all of Dave's methods, delegating to the
> underlying impl
> }
>
>

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland