modelconstraint - Dbquity model

page modified: 2024/08/11 22:33:25

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 <= l and l <= OuterRadius
                        where l: 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