25.01.2015 Views

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

Using Caché Objects - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A class inherits all of the specifications of its superclasses, including properties, methods,<br />

class parameters, applicable class keywords, and the parameters and keywords of the inherited<br />

properties and inherited methods. Except for items marked as Final, the subclass can override<br />

(but not delete) many of the characteristics of its inherited components.<br />

In addition to a class inheriting methods from its superclasses, the class' properties inherit<br />

additional methods from system property behavior classes and, in the case of a data type<br />

attribute, from the data type class.<br />

For example, if there is a class defined called Person:<br />

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

{<br />

Property Name As %String;<br />

Property DOB As %Date;<br />

}<br />

It's simple to derive a new class, Employee, from it:<br />

Class MyApp.Employee Extends Person [ClassType = persistent]<br />

{<br />

Property Salary As %Integer;<br />

Property Department As %String;<br />

}<br />

Inheritance<br />

This definition establishes the Employee class as a subclass of the Person class. In addition<br />

to its own class parameters, properties, and methods, the Employee class includes all of these<br />

elements from the Person class.<br />

Note:<br />

A class does not inherit the value of its superclass' ClassType keyword. You must<br />

explicitly specify this value in every subclass.<br />

You can use a subclass in any place in which you might use its superclass. For example, using<br />

the above defined Employee and Person classes, it is possible to open an Employee object<br />

and refer to it as a Person:<br />

Set x = ##class(MyApp.Person).%OpenId(id)<br />

Write x.Name // results in "Groucho Marx"<br />

We can also access Employee-specific attributes or methods:<br />

Write x.Salary // results in 22000<br />

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

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

Saved successfully!

Ooh no, something went wrong!