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

Non-fluent builder API #2

Open
Marcono1234 opened this issue Oct 17, 2022 · 1 comment
Open

Non-fluent builder API #2

Marcono1234 opened this issue Oct 17, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@Marcono1234
Copy link
Owner

Currently the builder only provides a fluent API. While this has some advantages it also have some disadvantages:

  • Bad IDE support:
    • Auto-formatting would remove proper indentation
    • Easy to make indentation mistakes, no help from the IDE
    • IDE type hints can make code very verbose (and possibly also decrease IDE reaction speed)
  • More difficult to break creation appart into separate steps

Therefore it might be useful to also offer a non-fluent builder API, for example similar to this:

byte[] serialData = serializableObject(
    classData(
        SerializableClass.class,
        List.of(
            intField("i", 6),
            objectField(
                "array",
                int[].class,
                array(new int[] {1, 2, 3})
            ),
            objectField(
                "s",
                String.class,
                string("nested-test")
            )
        )
    )
).createSerialData();

This could be realized in a rather user friendly way by exposing these static factory methods all on one class for which the user can then use a wildcard import (e.g. import static marcono1234...FactoryMethods.*;).

As part of this, it might be reasonable to rename the existing builders (and their packages) to:

  • SerialBuilder: FluentSerialBuilder / LowLevelFluentSerialBuilder (possibly a bit too verbose)
  • SimpleSerialBuilder: SimpleFluentSerialBuilder (too verbose?) / FluentSerialBuilder

The new builder API could be for now mostly be implemented on top of the existing fluent API. But eventually, especially for handle support, it might be easier to implement the fluent API on top of that new API. That would however also require a low level non-fluent API.

@Marcono1234 Marcono1234 added the enhancement New feature or request label Oct 17, 2022
Marcono1234 added a commit that referenced this issue Oct 17, 2022
TODO:
- Proper package names
- Proper tests
- Code generation support
- Renaming of existing builders (?)

Resolves #2
@Marcono1234
Copy link
Owner Author

The new API could for example be named CompositeSerialBuilder (?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant