-
Notifications
You must be signed in to change notification settings - Fork 182
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
Make it clear whether a built value can be a subclass of a class implementing Built #177
Comments
Right, the classes should only extend Object. But, it should be possible to allow 1) pulling in fields via "implements", 2) pulling in code via "with", i.e. mixins. Right now you can use "implements" to give classes common properties, but the code generation won't pick them up -- so you'll have to add the Similarly you should be able to use mixins to share implementation, but the code generation will ignore it. Does that work for what you want to do? Thanks! |
Ok, so the documentation could have this section: Hierarchical model
Is that about correct? Will this work? |
Yes, exactly. Just tried it and it works. I'll add to the docs plus an example in the code. Thanks! |
I just realized half of my built value classes actually extend from something else than Any issue that I'm not foreseeing? |
Extending relies on the class you're extending having a default constructor and no fields; in practice you should be able to use it as a mixin instead. You'll like this: https://github.com/google/built_value.dart/pull/186/files ... this adds automatically pulling in fields from interfaces, and makes it possible to create a non-instantiable Built to use as an interface. The example is probably the place to look: https://github.com/google/built_value.dart/pull/186/files#diff-8d9e54534132359b303e1bd4518fc99d I'll leave this open though because I should add docs as well as an example. |
This is me trying to figure out which docs/ Would it be possible to add a note to this thread, about where I can find clarification on this topic? |
I finally got to look at the code and it looks like
built_value_generator
works even when the class isn't directly implementingBuilt
. Somehow, I was under the impression that all value classes must be basically pure (no superclass exceptObject
). If I can use even just a little bit of inheritance to build several 'sibling' built values, that's amazingly helpful and definitely worth documenting. (Unless it's an anti-pattern, in which case it would be great to document why.)In particular, I'd like to know if something like this will work (and if that's a good idea):
If this will work, I'd like to understand:
A
's implement clause? If so, what should I put there?built_value_generator
that it shouldn't try to generate concrete class forA
? I assume by putting it in a class that's not in the Phases, but is there a better / different approach?@override
them explicitly inB
andC
(as shown above)?B
constructor any shorter using this approach?(This is sort of a continuation of #91.)
The text was updated successfully, but these errors were encountered: