Use of custom getters or setters

objectscriptQuality release 
1.0.0
Id 
OS0050
Rule type 
Code Smell
Severity 

Blocker

Blocker
SQALE characteristic 
  • Reliability
    • Instruction
Tags 
design, maintainability, reliability
Remediation function 
Constant/issue
Remediation cost 
1d

Given a property named, for instance, p in a class instance, ObjectScript automatically defines both getter and setter methods named, respectively, pGet() and pSet().

This means that the two following lines are equivalent:

    // Given an object instance o and a property p, write the value of p
    w o.p
    w o.pGet()

However, ObjectScript allows to override those methods. Consider the following:

    Class Test
    {
    Property p as %String [ InitialExpression = "foo" ];

    Method pGet() as %String
    {
        return i%p _ "bar"
    }

    ClassMethod m()
    {
        #dim t as Test
        set t = ##class(Test)..%New()
        w t.p, !
    }
    }

Executing method m from the class above actually prints foobar at the console.

Any such custom getter and setter can have any number of side effects; this makes code using such classes needlessly obfuscated for no good reason and is only confusing to the user of your code.

Get rid of this construct and propose an alternative method instead. If you do not want users to access the property directly, then make it both private and internal.