Defining and Using Classes
Introduction to Compiler Keywords
As shown in “Defining a Class: The Basics
,” you can include keywords in a class definition or in the definition of a class member. These keywords, also known as class attributes
, generally affect the compiler. This section introduces some common keywords and discusses how InterSystems IRIS presents them.
The following example shows a class definition with some commonly used keywords:
/// This sample persistent class represents a person.
Class MyApp.Person Extends %Persistent [ SqlTableName = MyAppPerson ]
/// Define a unique index for the SSN property.
Index SSNKey On SSN [ Unique ];
/// Name of the person.
Property Name As %String [ Required ];
/// Person's Social Security number.
Property SSN As %String(PATTERN = "3N1""-""2N1""-""4N") [ Required ];
This example shows the following keywords:
For the class definition, the Extends keyword specifies the superclass (or superclasses) from which this class inherits.
Note that the Extends keyword has a different name when you view the class in other ways; see the next section.
For the class definition, the SqlTableName keyword determines the name of the associated table, if the default name is not to be used. This keyword is meaningful only for persistent classes, which are described later in this book.
For the index definition, the Unique keyword causes InterSystems IRIS to enforce uniqueness on the property on which the index is based (SSN in this example).
For the two properties, the Required keyword causes InterSystems IRIS to require non-null values for the properties.
PATTERN is not a keyword but instead is a property parameter; notice that PATTERN is enclosed in parentheses, rather than square brackets.
Later chapters of this book discuss many additional keywords, but not all of them. Apart from keywords related to storage (which are not generally documented), you can find details on the keywords in the Class Definition Reference
. The reference information demonstrates the syntax that applies when you view a class in the usual edit mode.
Content Date/Time: 2019-09-19 06:44:29