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

Delegating constructors #3747

Closed
FMorschel opened this issue May 1, 2024 · 3 comments
Closed

Delegating constructors #3747

FMorschel opened this issue May 1, 2024 · 3 comments
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists

Comments

@FMorschel
Copy link

Today on the collection package we need a DelegatingList<E> class. All it does is receive a list and, as the name suggests, delegate all calls to methods, getters, setters and such to that specific list.

This week I had the same problem/need but with a FocusNode class. And I had to delegate 48 getters and setters to a base FocusNode. I'd like to propose a delegating constructor of sorts.

I imagine the syntax to be something like:

class A extends FocusNode {
  A(FocusNode f) : super = f;
}
@FMorschel FMorschel added the feature Proposed language feature that solves one or more problems label May 1, 2024
@lrhn
Copy link
Member

lrhn commented May 1, 2024

The thing you need is the ability to forward members of an interface to a specific object.

Consider something like:

class A implements FocusNode as _f {
  final FocusNode _f;
  A(this._f);
}

or

class A implements FocusNode{
  delegate FocusNode _f;
  final FocusNode _f;
  A(this._f);
}

or something similar, where a class defines that every method of an interface that it doesn't explicitly implement, is forwarded to an object which implements that interface.

I'm sure we have an issue for that already, but GitHub search being what it is, I haven't found it yet.

@FMorschel
Copy link
Author

FMorschel commented May 1, 2024

I think, I found what you were talking about #3748 (which being in the SDK could be why you didn't find it). I found the mention on #418 (comment) which is similar but I don't think this is the exact thing.

Should I move this discussion to one of those issues if they're what you were thinking?

@lrhn
Copy link
Member

lrhn commented May 2, 2024

I moved (now numbered) #3748 into the language repo, so let's defer to that.

@lrhn lrhn closed this as completed May 2, 2024
@lrhn lrhn added the state-duplicate This issue or pull request already exists label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants