5.2.2.4. Reference

<reference> is a sub element of object and defines a relation with another object in the same package. Inside this object scope the name of the reference has to be unique. An object can contain any number of references.

Listing 5.17 <reference/> example
 1<model>
 2        ...
 3
 4        <package name="yourModelPackage">
 5
 6                <object name="yourObjectName01">
 7                        ...
 8                        <reference name="yourReferenceName" type="nameOfReferencedObject" multiplicity="0..n" notnull="true"></reference>
 9                        ...
10                </object>
11        </package>
12
13        ...
14</model>

Syntax

<reference name=”” type=”” length=”” multiplicity=”” notnull=””> </reference>

Attributes

Table 5.20 attributes of <reference/>

Name

Details

Required

name

Name of the reference – has to be unique within the context of the object it is defined in.

mandatory

type

Data type of this reference (integer, boolean, string, other object…)

mandatory

multiplicity

Sets the multiplicity of the relation between the object of the reference and the object referred to.

multiplicity=”0..1| 1..1| 0..n| 1..n| n..n”

mandatory

notnull

This flag attribute tells whether its reference is allowed to be undefined (notnull=’FALSE”) or not (notnull=”TRUE”).

notnull=”false|true” with default “false”

optional

Exxample from the Bookstore application: an Author has a reference to Book, and the Book has references to Author and Category.

Listing 5.18 <reference/> example
 1<model>
 2
 3        <package name="domain">
 4
 5                <!--Assume we have authors who write books-->
 6                <object name="Author">
 7                        <attribute name="firstName" type="String" length="50" notnull="true" />
 8                        <attribute name="lastName" type="String" length="100" notnull="true" />
 9
10                        <reference name="book" type="Book" multiplicity="0..n"></reference>
11                </object>
12
13                <!--A book that is written by one author and the book belongs to a category-->
14                <object name="Book">
15                        <attribute name="name" type="String" length="100" notnull="true" />
16                        <attribute name="description" type="String" length="255" notnull="true" />
17
18                        <reference name="author" type="Author" multiplicity="1..1"></reference>
19                        <reference name="category" type="Category" multiplicity="0..1" notnull="false">
20                        </reference>
21                </object>
22
23                <object name="Category">
24                        <attribute name="name" type="String" notnull="true" length="20" />
25                        <attribute name="description" type="String" notnull="false" length="200" />
26                        <reference name="book" type="Book" multiplicity="0..n"></reference>
27                </object>
28        </package>
29</model>

Sub elements

Table 5.21 <package/> sub elements

Name

Details

Number

metadata

This element can contain properties that are specific to the package.

0..n