Symmetric associations

With symmetric links, the objects on both ends of the link know each other. Thus, two roles are defined.

The sample object model diagram, as shown in the following figure, shows a symmetric association between theFurnace and theRooms. This association is a to‑many link in which one furnace services three rooms.

Roles are implemented as:

Link data member

By default, a link is with a single instance. A link to a single instance is called scalar. A scalar relation is generated into a data member in the structure of the object whose name is the same as the role and whose type is a pointer to the other object. For example, an itsFurnace member of type pointer to Furnace is generated as a member of the Room structure to represent the Room's link to the Furnace:

struct Room {
    /***    User implicit entries    ***/
    struct Furnace * itsFurnace;
};

Link accessor

The link accessor returns a pointer to the associated object. Its name has the format <object>_get_<rolename>().

For example, the following accessor is generated for the itsFurnace role:

struct Furnace * Room_get_itsFurnace(const Room* 
    const me);

This is the implementation of the link accessor:

struct Furnace * Room_get_itsFurnace(
    const Room* const me)
{
    return (struct Furnace * )me->itsFurnace;
}

Link mutator

The link mutator sets a pointer to the associated object. If the link is symmetric, the mutator also sets the reciprocal link.

Up to three methods can be generated for the link mutator:


Feedback