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 />

Embeddable <strong>Objects</strong><br />

Note:<br />

<strong>Caché</strong> does not support polymorphic serial objects in persistent containers.<br />

3.2.3.1 Embedded <strong>Objects</strong> in Memory and on Disk<br />

When a new instance of an object containing an embedded object is created, the %New<br />

method (or the analogous New command in <strong>Caché</strong> Basic) automatically creates an in-memory<br />

instance of the object.<br />

For example, consider an Address class:<br />

Class MyApp.Address Extends %SerialObject [ClassType = serial]<br />

{<br />

Property Street As %String(MAXLEN=80);<br />

Property City As %String(MINLEN=3);<br />

Property State As %String(MINLEN=2);<br />

}<br />

Once defined, the Address class can be used as an embedded object attribute for a persistent<br />

object class such as Patient:<br />

Class MyApp.Patient Extends %Persistent [ClassType=persistent]<br />

{<br />

Property Name As %String;<br />

Property Home As Address;<br />

}<br />

In memory, this Home property can be used as any other object-valued property:<br />

// Open a persistent patient object<br />

Set patient = ##class(MyApp.Patient).%OpenId(22)<br />

// Get the patient's city and state from its Home address<br />

Set city = patient.Home.City<br />

Set state = patient.Home.State<br />

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

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

Saved successfully!

Ooh no, something went wrong!