Skip to content

Options should be immutable & use builder pattern. #148

Open
@michael-schnell

Description

@michael-schnell

It's a good style in Java to keep classes immutable if possible. This prevents accidential changes and makes them thread safe by design.

The "Options" classes like "DeleteStreamOptions" are currently mutable, which is kind of unexpected. It looks like a builder, but mutates the content of the instance:

DeleteStreamOptions opts = DeleteStreamOptions.get(); // Default
opts.softDelete(); // Now soft
opts.hardDelete(); // Now hard

I would suggest to create a real builder that returns an immutable instance.

Here is a short example of how the builder pattern would look like:
https://github.com/EventStore/EventStoreDB-Client-Java/compare/trunk...michael-schnell:issue-148?diff=split

If you think this is a good idea, I can create a pull request to discuss this further in detail in the PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions