tdiesler / fabric8poc

POC for the new Fabric8 API
Apache License 2.0
2 stars 5 forks source link

Add a nested profile builder inside the profile version builder #8

Closed iocanel closed 10 years ago

iocanel commented 10 years ago

Currently the ProfileVersionBuilder is able to create a ProfileBuilder which the user can use to create profile and add them to the version, like the snippet below:

ProfileVersionBuilder versionBuilder = ProfileVersionBuilder.Factory.create(version);
ProfileVersion linkedVersion = versionBuilder
                 .addProfile(versionBuilder.getProfileBuilder(identityA)
                         .addConfigurationItem("confItem", configA)
                         .build())
                 .addProfile(versionBuilder.getProfileBuilder(identityB)
                         .addParentProfile(identityA)
                         .addConfigurationItem("confItem", configB)
                         .build())
                 .build()

We could remove the need of carrying around the version builder instance by allowing the ProfileVersionBuilder to use a nested profile builder. The snippet above could become:

ProfileVersion linkedVersion = ProfileVersionBuilder.Factory.create(version)
                 .withProfile(identityA)
                         .addConfigurationItem("confItem", configA)
                  .and()
                 . withProfile(identityB)
                         .addParentProfile(identityA)
                         .addConfigurationItem("confItem", configB)
                  .and()
                 .build()

This is a small improvement in terms of cleaness, but does remove the burden of having to keep track which are the builder ones need to hold a reference to.

This PR adds the concept of composite/nested builder and applies it in the example above.

tdiesler commented 10 years ago

yes, fine