25.01.2015 Views

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Types of Classes<br />

3.2.1 Transient Object Classes<br />

Instantiations of classes derived from %RegisteredObject are known as registered or transient<br />

objects. These objects have a full set of built-in methods for controlling their in-memory<br />

behavior. (Most applications use persistent classes and embeddable classes rather than<br />

inheriting directly from %RegisteredObject.)<br />

Once you create an instance of a registered object, you can refer to it by its OREF (object<br />

reference). This system assigned value is transient; the value exists only while the object is<br />

in memory and is not guaranteed to be constant over different invocations.<br />

Registered objects use system allocated memory to store their values, and they support<br />

polymorphism.<br />

3.2.2 Persistent Object Classes<br />

Instantiations of classes derived from %Persistent are known as persistent objects; these<br />

objects are registered objects that inherit from the %Persistent class and have their ClassType<br />

keyword set to “persistent” . Persistent objects have the ability to store themselves into the<br />

database.<br />

Loading a persistent object into memory from the database does not load any other objects<br />

that it refers to. As soon as a referenced object is referred to, however, it is automatically<br />

brought into memory (this is known as “swizzling” or “lazy loading” ).<br />

When a persistent object is used as a property, it is referred to as a “reference” property.<br />

For example, if Doctor and Patient are persistent classes, you can define an attribute in the<br />

Patient class that uses Doctor as its type:<br />

Property TheDoc As Doctor;<br />

The property, TheDoc, is a reference property. The first time this property is referenced:<br />

Set doc = patient.TheDoc<br />

the appropriate Doctor object is loaded from the database automatically. In this example, doc<br />

will contain an OREF to the loaded Doctor object.<br />

You can chain together as many references as you like within one expression:<br />

Set location = patient.TheDoc.Hospital.Address.City<br />

If any of the objects referenced in such an expression is missing (null), then the entire<br />

expression will return a null value ("").<br />

<strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong> 17

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!