Home > Net >  Can the association ends have the same name?
Can the association ends have the same name?

Time:11-08

For example, imagine a diagram where there are 2 association ends such as incoming/outgoingRoads. Is it possible to store these roads together in the same arraylist by giving them the same name like "allRoads" that contains both incoming and outgoing?

Or is there other way to solve this?

naming both of them with same name in uml app brings no errors

CodePudding user response:

Two association ends at the opposite side of the same class are not allowed to have the same role name. It would create a naming ambiguity for City.allRoad:

enter image description here

Two association ends at the opposiste side of different classes can have the same role name. There would be no ambiguity between City.allRoad and WorkOrder.allRoad

enter image description here

Two ends of the same association can have the same role name as well. There would be no ambiguity between City.direction and Road.direction:

enter image description here

In the same way, there is no problem of having two associations between the same classes but with different end names:

enter image description here

Your design could as well deal with only one association for both incoming and outgoing roads. At least three different design could be considered:

  • making the road graph bidirectional, i.e. if all incoming routes are at the same time outgoing roads (caution: this is a substantial change in the underlying model: it would for example not allow to represent one-way roads)

  • using an association class, that would tell for each associated road, if it's incoming or outgoing.

    enter image description here

  • using a qualifier (which would probably be implemented as a map or a 2d array, as qwerty_so mentioned in the comments):

    enter image description here

  • Related