Immutability and Mutability
+ No thread locks
+ Fast read and lookup
– Bad for objects that highly mutable (increase memory usage every time it mutates)
+ Fast for highly mutable objects
+ Low memory footprint
– Thread locks
Where you use immutable/mutable depending on the objects and pattern utilized. Functional and Math programming requires immutability on all objects to ensure consistency with parallel execution. Object Oriented apps rarely needs immutability since object is reused over and over with high mutability.
1 very clear example of mutability : Try playing games and imagine if all the objects is immutable, including interaction between objects (player on terrain, player vs player, gravity simulation, etc) and if this immutable, how do you deal with the number of objects generated every time it mutates.
1 example for immutability : Math calculation that can be break down and spread across multiple parallel threads (calculating/simulating)