-
Enhancement
-
Resolution: Won't Fix
-
P4
-
fx2.0.2
-
None
A common use case for builders is to add an 'aspect' to them - i.e. a method that is added across all classes of a certain base type.
For example I will often want to add a builder method across all Nodes, such as setOnMouseOverAnimation, etc. Builders use a pretty fixed Java hierarchy so to implement such an aspect the developer has to extend every possible builder (LabelBuilder, ButtonBuilder, etc). It would be handy to have a way to do pseudo-mix-ins so that new methods could be easily added to base level builders without the need to extend everything.
This could be achieved through the use of interfaces and proxy classes that aggregate the sub-builders into one main builder.
Alternatively, there could be Builder chaining, where a Builder can have a "fall back builder" that should be used if the original base builder doesn't provide the method needed (on the fly inheritance). This approach would only be useful in FXML though as type-safe Java code would have no real advantage to using it. FXML would have to be enhanced to be aware of the base builder and use it (as would the tools like SceneBuilder in order to provide introspection).
Or if Builder chaining doesn't float your boat then potentially some way to set a postCreateHandler() on a builder that allows us to inject our own bit of logic into the builder after it has created a node. The FXML might look a little weird, something like:
<Button>
<text>My Button</text>
<postCreate>
<MouseOverAnimationAdder>
<MyCustomAnimation>
</MouseOverAnimationAdder>
</postCreate>
</Button>
Plenty of other options too, these are just some initial thoughts. Main goal is to allow aspects to be injected into Builders somehow.
For example I will often want to add a builder method across all Nodes, such as setOnMouseOverAnimation, etc. Builders use a pretty fixed Java hierarchy so to implement such an aspect the developer has to extend every possible builder (LabelBuilder, ButtonBuilder, etc). It would be handy to have a way to do pseudo-mix-ins so that new methods could be easily added to base level builders without the need to extend everything.
This could be achieved through the use of interfaces and proxy classes that aggregate the sub-builders into one main builder.
Alternatively, there could be Builder chaining, where a Builder can have a "fall back builder" that should be used if the original base builder doesn't provide the method needed (on the fly inheritance). This approach would only be useful in FXML though as type-safe Java code would have no real advantage to using it. FXML would have to be enhanced to be aware of the base builder and use it (as would the tools like SceneBuilder in order to provide introspection).
Or if Builder chaining doesn't float your boat then potentially some way to set a postCreateHandler() on a builder that allows us to inject our own bit of logic into the builder after it has created a node. The FXML might look a little weird, something like:
<Button>
<text>My Button</text>
<postCreate>
<MouseOverAnimationAdder>
<MyCustomAnimation>
</MouseOverAnimationAdder>
</postCreate>
</Button>
Plenty of other options too, these are just some initial thoughts. Main goal is to allow aspects to be injected into Builders somehow.