Class Definitions
Introduction
In Caché, a class can include familiar class elements such as properties, methods, and parameters (known as constants in other class languages). It can also include items not usually defined in classes, including triggers, queries, and indexes.
Details
A class definition has the following structure:
Import import_package_list Include include_code IncludeGenerator include_generator_code /// description Class package.shortclassname Extends superclass_list [ class_keyword_list ] { Class_members }
Where:
-
import_package_list (optional) specifies the names of any packages that you wish your class to import from. This affects how the compiler resolves short class names; see “Importing Packages” in Using Caché Objects.
This option, if specified, is either the name of a single package or is a comma-separated list of multiple packages, enclosed in parentheses.
If import_package_list is null, do not add the Import line at the start of the class definition.
Note:If a class imports any packages, that class does not automatically import the User package.
Imported packages are inherited from all superclasses. If a subclass specifies one or more import packages, those are added to any import packages defined by the superclasses.
-
include_code (optional) specifies Caché include (.inc) files used when compiling this class.
This option, if specified, is either the name of a single include file (without the .inc extension) or is a comma-separated list of multiple include files, enclosed in parentheses.
If include_code is null, omit the Include line at the start of the class definition.
For an introduction to include files, see “Include Files” in the InterSystems Programming Tools Index.
Include files are inherited from all superclasses. If a subclass specifies one or more include files, those are added to any include files defined by the superclasses.
-
include_generator_code (optional) specifies Caché include (.inc) files used when compiling the generator methods for this class. For information on generator methods, see “Defining Method and Trigger Generators” in Using Caché Objects.
For general comments, see the previous item.
If include_generator_code is null, do not add the IncludeGenerator line at the start of the class definition.
-
description (optional) is intended for display in the Class Reference. A description may consist of multiple lines and may include HTML formatting tags and additional tags such as <class> and <method>. For limitations and details, see “Creating Class Documentation” in Using Caché Objects. The description is blank by default.
-
package (required) is a valid package name, as described in “Package Names” in Using Caché Objects.
-
shortclassname (required) is a valid class name. Together, package and shortclassname form the complete class name, which is subject to a length restriction. See “Naming Conventions” in Using Caché Objects.
-
superclass_list (optional) specifies the class or classes from which this class inherits. This option, if specified, is either the name of a single class (without the .cls extension) or is a comma-separated list of classes, enclosed in parentheses.
The first such class is referred to as the primary superclass; any additional classes are secondary superclasses. For information, see “Inheritance” in Using Caché Objects.
If superclass_list is null, omit the word Extends from the class definition.
-
class_keyword_list (optional) is a comma-separated list of keywords that (in most cases) affect how the compiler generates code for this class definition.
See the section “Class Keywords.”
If this list is omitted, also omit the square brackets.
-
Class_members is zero or more definitions of class members.
For an introduction, see “Kinds of Class Members” in Using Caché Objects. The other sections in this reference provide details on these kinds of class member.
See Also
-
Defining and Compiling Classes in Using Caché Objects
This reference does not formally introduce storage definitions. For an introduction to storage definitions, see “Storage” in “Persistent Objects and Caché SQL” in the Caché Programming Orientation Guide. Also see “Storage Definitions and Storage Classes” in “Defining Persistent Classes” in Using Caché Objects.