Create a "class variable" and a "singleton".
Hi,
I tried to create what is know as a "class variable". As far as I understand the only analogy to class variables would be the "class parameters".
I tried to use a class parameter but I cannot change its value at runtime.
Parameter STATUSES = {{}};
{
w ##class(Test...).#STATUSES
w ..#STATUSES
...
}
When I get ..#STATUSES, it is a string like "5@%Library.DynamicObject". This is a string, not a pointer to an object.
I tried to define STATUSES as Parameter STATUSES and change the value with
d $system.OBJ.UpdateConfigParam("Test","STATUSES",{"a":10}) but it has no effect.
I need a class variable that is updated from %OnNew as a singleton . I try to make a class variable dictionary that keeps the instances defined so far.
My questions are, how to create a singleton and how to define a class variable ?
Greetings,
Comments
You may start checking this previous post:
Unable to store (or rather retrieve) OREF in globals - Trying to create a Singleton Class.
Thank you!
Thank you!
You cannot store {{}} as it is an object reference (oref) and the translation of the oref to a %String is not useful. You can try:
Parameter STATUSES = {{}}.%ToJSON();
and where you write 'w ..#STATUSES' you can instead write 'w [].%FromJSON(..#STATUSES)'
I assume you can also write 'w [].%FromJSON(##class(Test...).#STATUSES)' although I am not certain that will do what you desire. [[ There is an ancient request for "DWIM" software (Do What I Mean software) to replace "DWIS" software (Do What I Said software). ]]
And of course you Parameter modification can be written as:
d $system.OBJ.UpdateConfigParam("Test","STATUSES",{"a":10}.%ToJSON())
Thank you!
Thank you!