-
Notifications
You must be signed in to change notification settings - Fork 729
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
How to define a mutable object? #41
Comments
Assuming you meant immutable object here is my answer: If we use an immutable object, each time we want to modify any of its properties we are obliged to create a new instance of that class with the desired values. I also share with you an example for complementing my explanation.
|
Thank Cs4r, If MyObject has lots of properties, it will have a long construct method and the copy operation seems not clean. Is there any possible to use Dozer or other library to find a better way? |
If MyObject has lots of properties, the best thing you can do is to have a Builder in order to avoid telescoping constructors. Please see: https://github.com/cxxr/better-java#the-builder-pattern |
If we always use imitable object, how to change one filed value in this object? copy a instance ?
The text was updated successfully, but these errors were encountered: