After our discussion, we now know that an immutable object is an essential part of the functional programming. The following are the benefits we can get from the immutable object:
- We won't deal with the side effect. It's because we have ensured that no outside state is modified. We also create a new object every time we intend to change the value inside the object.
- There is no invalid object's state. It's because we will always be in an inconsistent state. If we forget to invoke a particular method, we will definitely get the correct state since there is no connection between methods.
- It will be thread-safe since we can run many methods together with no need to lock the first method that is run ...