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

Constructors #36

Closed
Lunaphied opened this issue Apr 7, 2015 · 6 comments
Closed

Constructors #36

Lunaphied opened this issue Apr 7, 2015 · 6 comments
Labels

Comments

@Lunaphied
Copy link

This isn't an issue so much as a question.

For Map implementation I can mix my interface into the vanilla MapColor, however I need to create instances of my interface to complete colors that aren't in the original enum (shades). I can work around this, but is it possible to just do new MixinMapColor(MapColor nmsMapColor, int shade)?
Or am I stuck with a static method that creates these?

Sorry if the explanation isn't very clear.

@Mumfrey
Copy link
Member

Mumfrey commented Apr 7, 2015

Under no circumstances should you add values to an existing enum, for the same reason as we don't use enums in the API. See this article which talks about doing it with reflection but ultimately the reasons are the same.

You cannot instance a mixin because a mixin isn't a class, it only makes sense in terms of its target, and in this particular scenario creating additional instances would be bad.

The recommended way of handling custom "constructor" logic would be to mix in a onConstructed hook using an injector, then do your custom logic there. It's not possible to add constructors to a target class using a mixin for obvious reasons.

If you're talking about creating "extra" [pseudo-enum] instances of your mixin, then the optimal solution is to have a surrogate class which also acts as a target for the mixin, and provides the additional values.

@Lunaphied
Copy link
Author

Ah, why would I add the surrogate class instead of just using the surrogate class and no mixin?

@Mumfrey
Copy link
Member

Mumfrey commented Apr 7, 2015

Because a surrogate allows you to reuse the code that you're mixing in to MapColour:

It's just an example of what's possible. I have no idea what your goal is so these are just random suggestions as to what you can try.

@Mumfrey
Copy link
Member

Mumfrey commented Apr 8, 2015

@modwizcode Do you need further assistance with this or can I close this issue?

@Lunaphied
Copy link
Author

Lunaphied commented Apr 8, 2015 via email

@Mumfrey
Copy link
Member

Mumfrey commented Apr 8, 2015

Ok cool, re-open if any further related queries.

@Mumfrey Mumfrey closed this as completed Apr 8, 2015
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants