Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-13

Use the builder pattern to create Bean objects

    XMLWordPrintable

Details

    • Feature Request
    • Resolution: Obsolete
    • Critical
    • None
    • None
    • None

    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

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              pmuiratbleepbleep Pete Muir (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: