next up previous contents index
Next: Order of declarations Up: Defining Classes Previous: Layout area

Dj-field declarations

A dj-field declaration in a class, which takes the following form, declares one or more components that comprise the class or attributes of the class:
    dj Type DJFieldDeclarator, ..., DJFieldDeclarator;
where the Type must be either an attribute type, a base class, or a user-defined DJ class, and each DJFieldDeclarator takes one of the following forms:
       Identifier                 (1)
       Identifier in Domain       (2)
       Identifier R expression    (3)
       Identifier ConstraintBlock (4)
where (2), (3), and (4) specify some constraints on the dj-field. Declarator (2), where Domain is an integer interval l..u or a list of values $\{a_1,a_2,...,a_n\}$, says that dj-field is equal to one of elements in the domain. Declarator (3), where R is an relation symbol (==, !=, >, >=, <, <=), says that the dj-field and expression satisfy the relation R. Declarator (4), where ConstraintBlock is a sequence of constraints in the form:
       {Constraint; ...; Constraint}
says that the dj-field satisfies the constraints.  

The following shows three examples:

       dj int w == rect.width;
       dj Color color in {red,black,white};
       dj int x in 0..9;
The first one declares an attribute, named width, and constrains it to be the same as rect.width where rect must be a component declared in the same class. The other two examples declare two attribute variables and specify their domains. Here are three more examples:
       dj Rectangle rect1, rect2{size == rect1.size};
       dj Label hw{text == "Hello World!"};
       dj Button bt{text == "Button"; x == y};
The first one declares two rectangles that have the same size; the second one declares a label whose text is "Hello World!"; and the third one declares a button whose x-y coordinates are the same.


next up previous contents index
Next: Order of declarations Up: Defining Classes Previous: Layout area
Neng-Fa Zhou
1999-02-16