In object-oriented and functional programming, immutable objects are objects whose state cannot be changed or altered after they are initiated. Therefore, a mutable object stays the same until the end of its life cycle, when it is de-initialized. In contrast, a mutable object can be altered countless times by other objects after it is initiated.
Immutable objects improve readability and runtime efficiency, and using them simplifies our applications.
This chapter will cover the concept of immutability by discussing the following topics with coding examples:
- Benefits of immutability
- Cases for mutability
- An example with approach comparisons
- Side-effects and unintended consequences
- Copy ...