class
or entity
When declared on a complex
(i.e. a class
or an entity
), a property
introduces a named value that can be set in the source model when declaring said complex
or any derived or mixing in complex
and retrieved using a runtime expression.
The value will be evaluated when parsed by the CLI and must be of a specified type
.
It may be further constrained when parsed by the CLI, if
constraint
property is declared by the property
value and/ormodelconstraint
property that refers to the property
is declared by the owning complex
or any derived or mixing in complex
.property <name>
type: <primitive>|<class-name>|<enumeration-name>
constraint: <expression> # evaluated when parsed by the CLI
type
Mandatory. Defines the type of the property value. Can be any of the primitives
or the name of an enumeration
or a class
.
constraint
Optional. Declares an expression, which must evaluate to true when the model setting the property value is parsed.
property
value on a complex
makes that complex
abstract, andcomplex
must either
abstract
(possibly by declaring another property
value), orproperty
values introduced by it's bases and mixins.Consider this library model, which introduces an abstract Ring
class, where the inner and outer radii of the ring are declared as property
values in the model source and then used in the static function Contains
to calculate whether a certain point (x,y) is contained within the ring:
library Ring
class Ring
property InnerRadius
type: real
constraint: . > 0
property OuterRadius
type: real
constraint: . > InnerRadius
function Contains
static
parameter x
parameter y
expression: InnerRadius <= r and r <= OuterRadius
where r: sqrt(x*x + y*y)
Now, to actually declare a concrete ring with specific inner and outer radii, we must inherit
Ring
and specify the InnerRadius
and OuterRadius
property
values.
For example:
site TwoRings
references: Ring
Ring OneToTwo
InnerRadius: 1
OuterRadius: 2
Ring TwoToThree
InnerRadius: 2
OuterRadius: 3
Finally, we can write an automated test to assert that the function Contains
works as expected:
test TwoRings
deployment: :TwoRings
assert:
OneToTwo.Contains(1,1);
not TwoToThree.Contains(1,1);
not OneToTwo.Contains(2,2);
TwoToThree.Contains(2,2)
act:
assertfailure Ring\Ring.Contains(1,1)
Notice how
Contains
fails if called onRing
, becauseRing
does not declare any values for its radii.