Are immutable properties supported in ObjectScript classes?
Can we make any property immutable once it value is set? For example, I may have a property called RecordCreatedTime to track when the record is created in IRIS, and once it is set, I don't want anyone to modify the value.
Product version: IRIS 2021.1
And use it as
Thanks for the response. I can see this is helpful in some of use cases!
1. If it's a one-off thing redefine your property setter:
It's also automatically set during object creation courtesy of InitialExpression, you can remove it if you want to set the value yourself.
2. If you have the same immutable property or a set of immutable properties you can write an abstract class:
And add it to inheritance whenever you need:
3. Finally if you have a lot of immutable properties and they are all different you'll need a custom datatype. Custom datatype defines method generators for getters, setters and all other property methods. Let's inherit from %String so we only need to redefine a setter:
Now we create a property of Test.ROString type:
And it would be immutable. In fact if we check a generated setter:
It would look quite similar to what I have wrote in (1), only automatically generated.
Thank you very much for the detailed responses! This is very helpful.