fmidev / fmi-avi-messageconverter

API classes for aviation weather message handling
MIT License
4 stars 6 forks source link

Ensure immutability in immutable model #104

Open petringo opened 1 year ago

petringo commented 1 year ago

Currently most of the immutable model objects allow setting arbitrary implementation of a property type, thus not enforcing immutability.

Specify the best suited convention to ensure immutability and implement it.

Some possible approaches:

  1. Override all required properties in immutable implementation, declaring the immutable type as property getter return value. This will enforce immutability already at compile time. But it will not work with generic types, e.g. optionals and collections. It will be a breaking API change.
  2. Override builder setters, test the value type and create an immutable copy when needed before setting the value. This behavior is not that transparent to the client. And is more work to implement.
  3. A combination of all previous.