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 constructor pseudo-method #13

Open
dead-claudia opened this issue Sep 6, 2017 · 4 comments
Open

Add constructor pseudo-method #13

dead-claudia opened this issue Sep 6, 2017 · 4 comments

Comments

@dead-claudia
Copy link

dead-claudia commented Sep 6, 2017

Kind of like how classes have constructors to run on initialization, it'd be nice to add a way to run code "on implement", since interfaces/protocols might wish to have their own state (for example, for caching) and/or branding that's more specific than just "this implements me" or "this implements that".

Notes:

  1. I'm not asking for arguments, which is something almost completely restricted to multiple-inheritance languages.
  2. Such code would be run on Reflect.implement call or right after super on its result, in order of appearance in classes.
  3. Any return value would be ignored.
@michaelficarra
Copy link
Member

I'm thinking that a feature like this would be more appropriate for a decorator. I remember we've discussed notifying classes about extension, but I don't remember much about those discussions. @wycats and @allenwb would know more.

@michaelficarra
Copy link
Member

Also, I'm generally opposed to the idea of a protocol being notified when it is implemented. I prefer explicit notification using existing mechanisms instead.

@dead-claudia
Copy link
Author

dead-claudia commented Sep 20, 2017 via email

@hax
Copy link
Member

hax commented Dec 12, 2017

@michaelficarra Could you give a code example to show how to provide protocol own states via decorator?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants