#3 The Principle of Immutability
This blog hails from the BC era — Before ChatGPT — and stands as a testament to enduring principles that transcend time.
The Principle of Immutability
As covered in previous blogs, my favorite software design and architecture principles are:
In this blog, I am going to cover the principle of immutability. This is the only principle that is not a side-effect of technology or framework among my core principles.
Immutability & Object-Oriented Design
The immutability principle is so universal that it can be appreciated at the most basic level and at the most advanced level. We can also look at it from an Object-Oriented programming perspective. Every object has a state and behavior. The internal state is its own business, and the only way an object should be modified is via behavior. The internal state of an object being hidden is called encapsulation.
Immutability takes this one step ahead with not even allowing the internal state of an object to be changed. In other words, if the internal state is changed, it’s no longer the same object. This new mutated object needs to be identified with a new identifier. If we use the language of security, it’s equivalent to an object having a different checksum. If we use the language of gitOps, it’s equivalent to an object having a new version.
In n-tier object-oriented design, the principle of immutability is most visible in the creation of data transfer objects or value objects.
Immutability & Gang of 4 Design Patterns
The principle of immutability intersects multiple Gang of 4 design patterns. The immutable artifact creation can be related to the factory method. Artifact cloning can be related to the prototype and memento pattern. Updating artifacts can be related to the state pattern.
领英推荐
Immutable Infrastructure & Environments
When designing the?Roost.ai?Test environments platform (our avatar in BC), one of the key considerations was how best we could provide immutable infrastructure for pre-production workloads. Following the pattern in the previous section, roost platform:
DD&IT Data Products | Assoc Director at Novartis
3 年Go4... still rocking... ;) Nice article.
Immutability really drives Domain Driven Principles and aggregates.