UML Tip: XOR in UML

Reading through the UML specifications I came across the XOR constraint (a UML predefined constraint). Thinking this would make a nice UML Tip nugget, I tried to dig deeper into this obscure little creature.

Lets have a look at four diagrams :

XOR (or an exclusive OR) is the only logical operator allowed in the UML, and is used on two or more discriminators (associations). It in effect is saying that only one of the two associations can exist at any one time.

Diagram 1. The first diagram shows how you would apply the XOR constraint to a UML diagram. Place the XOR in curly brackets and then link it up to the associations with dotted lines. The application of the XOR constraint makes sense in this first diagram, because a student can only attend one school at any one time. A particular student exclusively attends one or the other of these two schools. ‘Attends’ is an interesting word, however in my case, it is not saying that the student is physically inside the school grounds when it is attending. ‘Attends’ is a broader concept and does not involve the physicality of the student being somewhere. It is a bit like the word ‘Enrols’.

Diagram 2. The second diagram shows where you wouldn’t use the XOR constraint. In reality a student may apply to more than one university, so the XOR constraint would be wrong here.

Diagram 3. The third diagram shows an alternative to the first diagram. We can remove the two associations to the two schools and have only one association to the super class ‘School’. It is worth thinking about whenever you use a XOR constraint on two or more associations; should a single association with the super class replace the multiple associations? Is the XOR constraint indicative of a missing class?

Diagram 4. The fourth diagram shows a situation where you can’t generalize the associations. I guess, a true example where you would use the XOR constraint. Assuming that someone in this situation can either go to school or work (no after school jobs are allowed).


Posted in UML | Tagged , , | 2 Comments

2 Responses to UML Tip: XOR in UML

  1. felixzacat says:

    testing

  2. Naresh says:

    Nice article. 4th option gives more picture on how it works. I have one question, if the student has another option(Business), how do we accommodate in the diagram.

    thx,
    Naresh

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

THREE_COLUMN_PAGE