As per this link, it is an advice that:
A good object should never change his encapsulated state. Remember, an object is a representative of a real-life entity, and this entity should stay the same through the entire life of the object. In other words, an object should never betray those whom he represents. He should never change owners. :)
Be aware that immutability doesn't mean that all methods always return the same values. Instead, a good immutable object is very dynamic. However, he never changes his internal state.
Is it better to apply immutable property to re-introduce collections(in java) like class LinkedList rather than being mutable?
Without performance overheads, Can such collections( like LinkedList) be introduced as immutable collection?
Because, below are the advantages in favor of immutability:
- immutable objects are always thread-safe
- they help to avoid temporal
- coupling their usage is side-effect free