Question
· Dec 14, 2022

Property definition principles

Hi Guys,

I'm trying to get head around this principle of instance variables and the advantage of it.

I found this principle used a lot by my predecessor  in some properties definition and I'm wondering why don't we just use the property as simple as is, its creating two properties sCtg that contain the value and Ctg is a calculate to get the value of sCtg, is there advantage of fast accessing or... !?

and also the use or  DISPLAYLIST &  VALUELIST does this brings any advantage vs defining a standard property (eg.fast access!), so instead of have to do Valuetist "H" and Dispay "Hot" why just a standard property as string containing "Hot"?

Property Ctg As %Text(MAXLEN = 256) [ Calculated, SqlComputeCode = { Set {Ctg}=##class(MSDS.Serenity.Kit).GetKitCtg({ID})}, SqlComputed ];

Property sCtg As %Text(MAXLEN = 256);

ClassMethod GetKitCtg(kitId As %String) As %String
{
  set oCK = ..%OpenId( kitId)
  quit:'$isObject( oCK) ""
  quit oCK.Ctg
}

Method CtgGet() As %Text
{
  quit i%sCtg
} 

Method CtgSet(name As %Text) As %Status
{
  set i%sCtg = name
  quit $$$OK
}

 

Thanks

Product version: Ensemble 2014.1
Discussion (3)2
Log in or sign up to continue

I'll start from the simplier one:

and also the use or  DISPLAYLIST &  VALUELIST does this brings any advantage vs defining a standard property (eg.fast access!), so instead of have to do Valuetist "H" and Dispay "Hot" why just a standard property as string containing "Hot"?

More effective storage. If you can replace Cold with 1, Medium with 2 and Hot with 3 you can save some space. Another reason is that VALUELIST turns a string into a enum, which changes the logic considerably.

Frankly I cannot see any advantage in using the sample you posted, it makes things more complicated with no advantage and no, it's not faster than just use a plain simple property.

There are cases when those "tricks" (calculated properties, Set/Get methods) can be useful, but that's not the case of the code in your sample.

Regarding VALUELIST, it makes it easy and simple to define a (typically small) set of valid values for a property, then, if necessary, you can optionally provide a "user friendly" representation of those value. If you don't find it useful or don't need it, well....don't use it.

Enrico