What is deep immutability?

Viewed 1178

When reading the Promises/A+ specification I came across the term 'deep immutability'. The text says:

Here, “must not change” means immutable identity (i.e. ===), but does not imply deep immutability.

What is deep immutability? Can someone explain with an example?

2 Answers

In Object Oriented Languages, there is no good way to lock the objects propertys. For example, if you have multiple instantiations of an object in your app, and you change a property value on one of those references, then the data now differs between at least one of the references of that object. Deeply Immutable ensures that the data for that object stays locked, programmatically, by spec, across all references.

If the application specs state deep immutability, then it would be illegal to either mutate the object, or reassign its fields.

If the application states shallow immutability, you still cant reassign the objects fields, hence immutable, but you are allowed to mutate the objects references.

There is a great article on this here https://homes.cs.washington.edu/~mernst/pubs/immutability-aliasing-2013-lncs7850.pdf

According to the article, most clients prefer deep immatibility.

Related