Tech Tip: Computed Properties in 4D Classes: When and How Getters/Setters Execute
PRODUCT: 4D | VERSION: 20 R | PLATFORM: Mac & Win
Published On: October 1, 2025
In 4D development, a common ambiguity arises around computed properties in classes—specifically, when their code runs and why they don't always store data in memory. This can lead to unexpected behavior if you're assuming they're like persistent properties. Computed properties are ideal for derived values (e.g., calculating net price from gross price and VAT) that shouldn't consume memory until accessed.
Function get executes only on read, and Function set only on write. If never accessed, nothing runs.
Example :
Test usage:
Function get executes only on read, and Function set only on write. If never accessed, nothing runs.
Example :
//Class: Value property name : Text property _value : Variant Class constructor($name : Text) This.name:=$name Function set value($value : Variant) This._value:=$value Function get value()->$value : Variant $value:=This._value |
Test usage:
//Method: TestValue $test:=cs.Value.new("myName") $test.value:=123 |