4.2 Value objects

A value object is either constant or variable .

Constant

A constant value object declaration has the form:

name: val ObjectDescriptor

where name is the name of the objects and ObjectDescriptor is a description of the value object. The ObjectDescriptor is executed when the data-item is generated as part of the generation of the enclosing object. The value object is embedded in the object containing the declaration – called the holder of the value object.

An object described by an ObjectDescriptor where the items-part is non-empty – i.e. n >= 1, is called a singular object.

Examples

V1: val 7
V2: val Point(3,4 + y)
V3: val -- singular example

V1, V2, and V3 are value objects. V3 and O3 is a singular object.

Variable value object

A variable object declaration has the form:

name: var ObjectDescriptor

where name is the name a value object as described by ObjectDescriptor. The ObjectDescriptor is executed when the data-item is generated as part of the generation of the enclosing object. The value object is embedded in the object containing the declaration – called the holder of the value object.

Difference for object reference

There is an important difference between a reference and a value object with respect to being constant or variable.

  • A constant object reference refers to the same object using the whole of a program execution.
  • A variable object reference may refer to different objects during a program execution.
  • For constant or variable value object, the value object is generated as part of generation of the holder and it is the same object during the whole program execution.
  • For a constant value object, the state of the object is detrained when the value object is generated and cannot be changed during a program execution.
  • For a variable value object, the state of the value object can be changed during a program execution.

Examples

V1: var integer --  or integer(0), integer()??
V2: var integer(7) -- the initial value of V2 is 7
V3: var Point(3,4) -- the initial value is an instance of Point(3,4)

Hello world