property
valuesDeclares an expression
over modeling property
values, which will fail parsing, if it yields false
or nil
.
Referring to the Ring library, which is introduced for the property
example,
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)
we may declare a thin ring with a modelconstraint
stating that the ring is no thicker than a tenth of the inner radius:
site ThinRing
references: Ring
Ring ThinRing
abstract # because we set no values for inner and outer radii
modelconstraint:OuterRadius <= InnerRadius * 1.10
ThinRing TenToEleven
InnerRadius: 10
OuterRadius: 11
ThinRing NineToTenIsNotThinEnough
InnerRadius: 9
OuterRadius: 10
Note, that
to avoid a parsing error,
ThinRing
must be declaredabstract
, because it does not specify values for its radii whose constraint expressions would fail for a non-abstract class, and thatparsing the last sample class,
NineToTenIsNotThinEnough
, will fail thus:C:\Web\dbquity.com\model>dbquity parse ThinRing * Dbquity CLI v0.10.8676 parse ThinRing * Scanning references: ThinRing: ThinRing -> Ring Ring: Ring => sources: Ring ThinRing Parsing Ring.dbquity: library Ring...... validating library Ring........ok Parsing ThinRing.dbquity: site ThinRing... validating site ThinRing......failed! Error: Failed to validate site ThinRing. Warning: site ThinRing: No entities defined. Error: ThinRing NineToTenIsNotThinEnough.modelconstraint: 'OuterRadius <= InnerRadius * 1.10' is not fulfilled.