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

Options should be immutable & use builder pattern. #148

Open
michael-schnell opened this issue May 28, 2022 · 0 comments
Open

Options should be immutable & use builder pattern. #148

michael-schnell opened this issue May 28, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@michael-schnell
Copy link

michael-schnell commented May 28, 2022

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.

@ylorph ylorph added the enhancement New feature or request label Mar 15, 2023
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

No branches or pull requests

2 participants