modelconstraint - Dbquity model

page modified: 2024/10/10 14:05:04

Constraint on modeling property values

Declares an expression over modeling property values, which will fail parsing, if it yields false or nil.

Example

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