Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-generate BuilderConstructors #4

Closed
arjanvlek opened this issue Jan 14, 2019 · 1 comment
Closed

Auto-generate BuilderConstructors #4

arjanvlek opened this issue Jan 14, 2019 · 1 comment

Comments

@arjanvlek
Copy link
Contributor

arjanvlek commented Jan 14, 2019

Currently, when creating a builder by extending from AbstractBuilder, it is required to implement the method constructors(), which returns an instance of BeanConstructors for your builder.

However, from practice it seems that almost always the same pattern to make an instance of builderConstructors is used. That pattern is the following:

in the BuildCommand class:

public class MyBuildCommand extends AbstractBuildCommand<MyEntity> {

    public MyBuildCommand(MyEntity entity) {
        super(entity);
    }

     public MyBuildCommand(Supplier<MyEntity> entity) {
        super(entity);
    }

  { ... }
}

in the Builder class:

@Override
public BuilderConstructors<MyEntity, MyBuildCommand> constructors() {
    return new BuilderConstructors<>(
            MyBuildCommand::new,
            MyBuildCommand::new,
            MyEntity::new
    );
}

By auto-generating the BuilderConstructors definition the method override and the 2 constructors in MyBuildCommand can be omitted from a builder.

arjanvlek added a commit that referenced this issue Jan 14, 2019
AbstractBuilder can now automatically generate the required
`BuilderConstructors` used to obtain references to a `BuildCommand` given an
Entity. This is done by accessing the no-args constructor of the entity
and the BuildCommand class.

For customization and backwards compatibility, it's still possible to
override the `constructors()` method of `AbstractBuilder` and supply
your own set of `BuilderConstructors`

Fixes #4
arjanvlek added a commit that referenced this issue Jan 17, 2019
AbstractBuilder can now automatically generate the required
`BuilderConstructors` used to obtain references to a `BuildCommand` given an
Entity. This is done by accessing the no-args constructor of the entity
and the BuildCommand class.

For customization and backwards compatibility, it's still possible to
override the `constructors()` method of `AbstractBuilder` and supply
your own set of `BuilderConstructors`

Fixes #4
@arjanvlek
Copy link
Contributor Author

Fixed in ca1f399

arjanvlek added a commit that referenced this issue Jan 25, 2019
AbstractBuilder can now automatically generate the required
`BuilderConstructors` used to obtain references to a `BuildCommand` given an
Entity. This is done by accessing the no-args constructor of the entity
and the BuildCommand class.

For customization and backwards compatibility, it's still possible to
override the `constructors()` method of `AbstractBuilder` and supply
your own set of `BuilderConstructors`

Fixes #4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant