An Immutable class whose instances never change. The state of the object is defined at construction time and never changes after.
To be properly immutable, the class doesn't provide any way (other than reflection) to change its state: no setter method, no method that changes its internal state, no method that allows accessing to a mutable field it holds. It should also be final (as BigDecimal should be), to prevent any other class to extend it and thus make it mutable by adding mutable fields.
The advantages are many:
- The class is easy to understand
- Instances are inherently thread-safe
- Instances can be cached without needing to return copies from the cache
- Instances can be used as keys in a Map without fear of being changed after
It doesn't violate OO principles: to the contrary, the state is completely encapsulated in the object.
Note: some immutable objects change their state internally (lazy initialization of some fields, for example) without affecting the externally-visible state of the object. If done properly, it doesn't change the thread-safety of immutable objects. If done incorrectly, it can make them non-thread-safe.