property - Dbquity model BETA

page modified: 2024/10/10 15:21:22

A named modeling value to be set on a 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

Declaration

property <name>
    type: <primitive>|<class-name>|<enumeration-name>
    constraint: <expression>    # evaluated when parsed by the CLI

Properties

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.

Implications

Example

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 on Ring, because Ring does not declare any values for its radii.