Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add language-level support for object forwarding #20705

Closed
DartBot opened this issue Aug 27, 2014 · 5 comments
Closed

Add language-level support for object forwarding #20705

DartBot opened this issue Aug 27, 2014 · 5 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Aug 27, 2014

This issue was originally filed by @yissachar


Object delegation is a common solution when inheritance is not an option. For instance, before ListBase was introduced, one option to get around inheriting List was to use a delegate list and then forward all the method calls. Forwarding the method calls can be done manually, which is tedious. Alternatively, forwarding can quickly be accomplished with noSuchMethod at the cost of tooling support (since the analyzer no longer can verify your calls) and potential code size issues when deploying to JavaScript.

Language-level support for this common pattern would provide the advantages of manual delegation without forcing the user to type out every method.

One possible implementation would be through a "proxy" keyword or something similar that would indicate a field is to be delegated.

class MyList {
  proxy _list = [0, 1, 2];
}

var myList = new MyList();
myList.add(3);
print(myList.length);

Multiple proxies for a class would not be allowed if they would cause ambiguity, but could be allowed otherwise (e.g. proxying two Lists would not be allowed since there would be no way to determine which to delegate to, but proxying List alongside Foo which does not share any method signatures would be fine).

@dgrove
Copy link
Contributor

dgrove commented Aug 27, 2014

Added Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Aug 27, 2014

There is some question if we are talking about delegation or just forwarding. It sounds like forwarding in this case.


Set owner to @gbracha.
Added Accepted label.
Changed the title to: "Add language-level support for object forwarding".

@DartBot
Copy link
Author

DartBot commented Aug 28, 2014

This comment was originally written by @yissachar


Yes, I mean forwarding only. Sorry for confusing the terms.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Aug 28, 2014
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed accepted labels Feb 29, 2016
@Aetet
Copy link

Aetet commented Nov 6, 2016

How this issue can be solved with existing tools at dart? Is it possible?

@natebosch
Copy link
Member

Unfortunately I didn't see this issue when I filed dart-lang/language#3748 with a very similar request. Since that issue has more discussion I think we should use it to track any decisions on this going forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants