1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| In the UML model above, the links with black diamonds on them are containment
relations.
For example, an Individual can be contained either by a Family or by a
FamilyTree.
An object can only have one container. For example, the relations between
Family and Individual defined in the previous section are not containment
relations - because people can be married more than once (even if generally
not at the same time).
When instances of this model are created using the editor generated by EMF,
there will be a single top-level FamilyTree object and all the other objects
in the model will be contained by it, directly or indirectly. The model
cannot be saved correctly if there are objects which have no container.
Add the following methods to FamilyTree to define its containment relations:
/**
* Return a list of contained families
* @model type="Family" containment="true"
**/
java.util.List getFamilies();
/**
* Return a list of contained individuals
* @model type="Individual" containment="true"
**/
java.util.List getIndividuals();
Unlike the simple references defined in the previous section, these methods
return Lists - thats because a FamilyTree can contain multiple Families and
Individuals. The return type must be java.util.List or
org.eclipse.emf.common.util.EList so that EMF recognizes that
this is meant to be multi-valued. Notice the @model tag declares the type of
object that can appear in the List. In addition, the flag containment="true"
indicates that this is a containment relation. |
Partager