This is my 15th activity to participate in the August Challenge
Chapter 101. Attribute keyword – InitialExpression
Specifies the initial value for this property.
usage
To specify an initial value for this property, use the following syntax:
Property name As classname [ InitialExpression = initialexpression ];
Copy the code
Where initialExpression is a constant or ObjectScript expression enclosed in curly braces.
Break down
This keyword specifies the initial value of the property. This value is assigned by the class’s %New() method when a New instance is created. (If the property is transient, its initial value is determined by the code called %New() when the instance is created or %OpenId() when the instance is loaded from disk into memory.)
The value of the initial expression must fit the given attribute type.
Expressions can be arbitrarily complex, with the following restrictions:
- The initial expression cannot reference other attributes. In other words, such as {
..therPropertyname
} such an expression is invalid. - An initial expression cannot instantiate an object, nor can it include an object reference.
- Initial expressions cannot call instance methods (only class methods).
- You must specify the initial expression in ObjectScript.
- Code executed by expressions should not report errors. InterSystems IRIS does not provide a way to handle errors returned by expressions.
- If the expression executes code that causes additional processing to occur, InterSystems IRIS does not provide a way to process the result of that processing.
Subclasses inherit the value of the InitialExpression keyword and can override it.
The default
InitialExpression the default value of the keyword is NULL.
The sample
Several examples of using ObjectScript expressions are shown below:
Property DateTime As %Date [ InitialExpression = {$zdateh("1966-10-28".3)}]; Property MyString As %String [ InitialExpression = {$char(0)}];/// This parameter is initialized with the parameter value
Property MyProp As %String [ InitialExpression = {..#MYPARM} ];
/// This is initialized by a class method
Property MyProp2 As %Numeric [ InitialExpression = {..Initialize()} ];
Copy the code
Chapter 102 attributes keyword – Internal
Specifies whether this property definition is internal (not shown in the class document).
usage
To specify this property as internal, use the following syntax:
Property propertyname As classname [ Internal ];
Copy the code
Otherwise, omit the keyword or place it before the keyword.
Break down
Inner class members are not displayed in the class document. This keyword is useful if you want the user to see a class, but not all of its members.
The default
If this keyword is omitted, the property is displayed in the class document.
Chapter 103. The attribute keyword – Inverse
Specifies the opposite of this relationship. Relationship properties require. Not used for other attributes.
usage
To specify a relationship property in a related class that is the opposite of the relationship property, use the following syntax:
Relationship Chapters As Chapter [ Cardinality = cardinality; Inverse = inverse ];
Copy the code
Where Inverse is the name of the attribute in the related class.
Break down
This keyword specifies the name of the opposite side of the relationship, that is, the name of the corresponding relationship property in the related class. The reverse attribute must exist in the related class and have the correct cardinality value.
The Inverse keyword is required for relational properties. Non-relational properties ignore it.
The default
There is no default value. When defining a relationship, you must specify the reverse keyword.
The sample
Relationship Chapters As Chapter [ Cardinality = many; inverse = Book ];
Copy the code
Chapter 104 Properties Keywords – Emotions
Specifies that this property has the characteristics of a multidimensional array.
usage
To specify that this property has the characteristics of a multidimensional array, use the following syntax:
Property Data [ Multidimensional ];
Copy the code
Otherwise, omit this keyword or place the word Not before it.
Break down
Multidimensional attributes differ from other attributes as follows:
- IRIS does not provide attribute methods for this.
- When an object is validated or saved, it is ignored.
- It is not saved to disk unless the application contains code specifically to save it. That is, properties are also automatically transient.
- It cannot be exposed to Java or other clients.
- It cannot be stored in or exposed through SQL tables.
Multidimensional attributes are rare, but they provide a useful way to temporarily include information about an object’s state.
The default
If this keyword is omitted, the attribute is not multidimensional.