Question
· Sep 26

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 = {{}};

Property repr As %String;

Method %OnNew(repr) As %Status
{
    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  As CONFIGVALUE = {{}};  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,

Product version: IRIS 2024.1
$ZV: IRIS for Windows (x86-64) 2024.1 (Build 267_2) Tue Apr 30 2024 16:37:07 EDT
Discussion (6)3
Log in or sign up to continue

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())