Skip to main content

Property Accessors for Literal Properties

Property Accessors for Literal Properties

The Caché dot syntax for referring to object properties is an interface for a set of accessor methods to retrieve and set values. For each non-calculated property, whenever the code refers to oref.Prop (where oref is an object and Prop is a property), it is executed as if a system-supplied PropGet() or PropSet() method were invoked. For example:

 Set person.DOB = x

acts as if the following method was called:

 Do person.DOBSet(x)

while:

 Write person.Name

acts like:

 Write person.NameGet()

In most cases, you cannot see the actual PropGet() and PropSet() methods; access for simple properties is implemented directly within the Caché virtual machine for optimal performance. You can, however, provide PropGet() and PropSet() methods for a specific property, as long as that property is not object-typed or multidimensional. If you define these methods, the system automatically invokes them at runtime. The following sections describe how to define these accessor methods. Within the custom methods, you can perform any special processing that your application requires.

Note that the last screen of the New Property Wizard in Studio provides options for creating a custom Get() method, Set(), or both. If you use these options, Studio defines stub methods with suitable signatures.

Accessing the properties of an object by using the PropGet() and PropSet() methods requires that the object be loaded into memory. On the other hand, the PropGetStored() method allows you to retrieve the property value of a stored object directly from disk, without having to load the entire object into memory. For example, to write the name of the person with ID 44, you could use:

 Write ##class(MyApp.Person).NameGetStored(44)
FeedbackOpens in a new tab