Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Make ProfileBuilder more friendly. #6

Closed
iocanel opened this issue Apr 29, 2014 · 2 comments
Closed

Make ProfileBuilder more friendly. #6

iocanel opened this issue Apr 29, 2014 · 2 comments

Comments

@iocanel
Copy link
Contributor

iocanel commented Apr 29, 2014

The profile builder needs to be improved and become more friendly / DSL-y

Currently the builder works like this:

ProfileBuilder.Factory pb = ProfileBuilder.Factory.create(id);
ConfigurationProfileItem item1 = pb.getProfileItemBuilder("id1", ConfigurationProfileItemBuilder.class).setConfiguration(map1);
ConfigurationProfileItem item2 = pb.getProfileItemBuilder("id2", ConfigurationProfileItemBuilder.class).setConfiguration(map2);

Profile p = pb
    .addAttributes(attributes)
    .addProfileItem(item1)
    .addProfileItem(item2)
    .build();

With the above approach there are two issues:
i) A lot of boilerplate.
ii) I need to hold a reference of the ProfileBuilder in order to create a ConfigProfileItem and this spoils the DSL-y style of the builder.

Since the builder knows what profile items and profile item builders it supports. It should be like:

Profile p = ProfileBuilder.Factory.create(id)
    .addAttributes(attributes)
    .addConfiguration("id1", map1)
    .addConfiguration("id2", map2)
    .build();

or

Profile p = ProfileBuilder.Factory.create(id)
    .addAttributes(attributes)
    .addProfileItem(ConfigurationProfileItemBuilder.Factory.create("id1", map1)
    .addProfileItem(ConfigurationProfileItemBuilder.Factory.create("id2", map2)
    .build();

I think I prefer the first alternative, or a combination of the two.

@tdiesler
Copy link
Owner

Yes, approach one is good. It encodes the set of possible profile items in the PB signature. We are likely going to have less than a handful PI types, so its ok to have individual methods. The second approach is not so good because it promotes the PIB to a top level thing - it should however be a sub builder, like PI is a subtype of P.

tdiesler pushed a commit that referenced this issue May 2, 2014
#6 Remove generic getProfileItemBuilder from ProfileBuilder. Add addConf...
@tdiesler
Copy link
Owner

tdiesler commented May 2, 2014

Resolved

@tdiesler tdiesler closed this as completed May 2, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants