[
https://issues.jboss.org/browse/WELD-13?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Pete Muir updated WELD-13:
--------------------------
Summary: Use the builder pattern to create Bean objects (was: Switch
to using a builder to make immutable bean objects)
Priority: Critical (was: Major)
Description:
Currently we create the Bean objects using a two phase initialization, partly
via the constructor, and partly via an initialize() method, this allows us to
create the beans, attach them to the bean manager and then do further work once
all bean objects exist. This has a number of problems:
1) objects are not fully immutable which means we rely on developers ability to
keep them effectively immutable
2) the objects are a mess of init methods and getters
3) creation logic is convoluted
It would be far better to create builders (or factories) that can create the
beans as needed, this will cleanly split out the creation logic from the bean
object, and allow us to create fully immutable objects, thus making it easier
to verify the thread-safety of the code.
A side effect of this will be that we can't use two-phase initialization two
set up certain stuff after all beans are present. To overcome this we will need
to order the bean creation so that beans required by other beans are created
first and thus can be attached as needed.
The rules I am aware of:
* producer methods and fields should be created after the class bean that
declares them as they need to know that bean in order to be instantiated
* specialized beans need to be created in the order least specialized to most
specialized as a more specialized bean needs to read the metadata of the less
specialized bean
was:
Currently we do a lot of init in the *Bean which, to be flexible, isn't in the
constructor, which stops the Bean objects being truly immutable. It's also not
nice to read.
A challenge will be the two phase bootstrap.
I would recommend doing this refactor early on as it will make the code base
much more manageable.
> Use the builder pattern to create Bean objects
> ----------------------------------------------
>
> Key: WELD-13
> URL: https://issues.jboss.org/browse/WELD-13
> Project: Weld
> Issue Type: Feature Request
> Components: Class Beans (Managed and Session)
> Reporter: Pete Muir
> Priority: Critical
> Fix For: 1.2.0.Beta1
>
>
> Currently we create the Bean objects using a two phase initialization, partly
> via the constructor, and partly via an initialize() method, this allows us to
> create the beans, attach them to the bean manager and then do further work
> once all bean objects exist. This has a number of problems:
> 1) objects are not fully immutable which means we rely on developers ability
> to keep them effectively immutable
> 2) the objects are a mess of init methods and getters
> 3) creation logic is convoluted
> It would be far better to create builders (or factories) that can create the
> beans as needed, this will cleanly split out the creation logic from the bean
> object, and allow us to create fully immutable objects, thus making it easier
> to verify the thread-safety of the code.
> A side effect of this will be that we can't use two-phase initialization two
> set up certain stuff after all beans are present. To overcome this we will
> need to order the bean creation so that beans required by other beans are
> created first and thus can be attached as needed.
> The rules I am aware of:
> * producer methods and fields should be created after the class bean that
> declares them as they need to know that bean in order to be instantiated
> * specialized beans need to be created in the order least specialized to most
> specialized as a more specialized bean needs to read the metadata of the less
> specialized bean
--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
weld-issues mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/weld-issues