oliviercoma / fluent-builders-generator-eclipse-plugin

Automatically exported from code.google.com/p/fluent-builders-generator-eclipse-plugin
0 stars 0 forks source link

Ability to generate a parent Builder #18

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Is it possible to generate a parent builder class that references and invoke 
all the generated builders?

It will lead to something like this.

Given two model Classes: User and Account
Actually, FB generates two builder, UserBuilder and AccountBuilder, that allow 
this:

Account ac = AccountBuilder.account().withNumber("555-...").build();
and
user u = UserBuilder.user().withName("toto").withAccount(ac).build();

My purpose is the ability to generates a parent builder.
The code will now seem like this:
Account ac = Builder.account().withNumber("555-...").build();
and 
User u = Builder.user().withName("toto").withAccount(ac).build();

Here, we don't reference any specific Builder but the generic.

Its implementation will seem like this:

public class Builder {
public static UserBuilder user() {
return UserBuilder.user();}
public static Account Builder user() {
return Account Builder.account();}
}

An alternative is something with generics like

Builder<User>.instance().withName("toto").build();

It may be more difficult to implement, but a little more usable isn't it?

It's just a little improvement, but it could be clever ;).

Regards, thank you for this nice plugin.

Tcharl

Original issue reported on code.google.com by CMorda...@gmail.com on 5 Dec 2011 at 1:43