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

Make Name properly immutable #160

Open
nresare opened this issue Feb 5, 2021 · 1 comment
Open

Make Name properly immutable #160

nresare opened this issue Feb 5, 2021 · 1 comment

Comments

@nresare
Copy link
Member

nresare commented Feb 5, 2021

The public API of Name is immutable, meaning that there are no methods that can be used to change the state of a Name instance once constructed. However, as an implementation detail of how the public constructors populate the fields of the class, they end up calling private api that modifies state repeatedly.

Having only final fields in immutable objects is good house keeping, but unfortunately test coverage is not very high for Name so it is a bit scary to do refactoring work. Getting to, or close to 100% unit test coverage and then update the implementation to allow for using the final modifier with all fields would be a neat contribution in my opinion.

@ibauersachs
Copy link
Member

I made significant changes to Name in fecf898, among others a Name derived from another no longer shares the same data.

While full immutability would be a nice to have, I don't think it'd be wort the effort and trade-offs. All methods called from the constructor would need to be static, require intermediate objects for the to-be-final fields (due to the lack of multiple return or out-values in Java).

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

No branches or pull requests

2 participants