Frozen Dataclasses
Learn the concept of frozen dataclasses and their implementation in Python.
We'll cover the following...
Overview
The general case for dataclasses is to create mutable objects. The state of an object can be changed by assigning new values to the attributes. This isn’t always a desirable feature, and we can make a dataclass immutable.
We can describe the UML diagram of the design by adding a stereotype of «Frozen»
. This notation can help to remind us of the implementation choice of making the object immutable. We must also respect an important rule of frozen dataclasses: an extension via inheritance must also be frozen.
The definition of the frozen Sample
objects ...