Hairi
Hairi

Reputation: 3733

How to specify structure in which order matters in a class diagram

In my previous question I was trying to achieve the idea of ordering the classes. Although the example I presented wasn't appropriate.

So here is the situation I want to ascribe by UML class diagram:

In ODT document I have something called figure. The figure is comprised of two atomic elements: image and title(of the image). The standard allows me to put the title, either on top of the image or bellow the it. Although In my application the title will always be beneath the image like this:

enter image description here

So in my case I want to submit the (more specific) information that the title must be beneath the image (although the standard does not obligate so). Thus I came up to the idea of making order in my class diagram (this is first, then this, then this, etc...). Because in my case that matters.

Here is my despaired attempt:

enter image description here

Is there any approach to present that information through a UML Class Diagram?

Upvotes: 1

Views: 890

Answers (1)

Jim L.
Jim L.

Reputation: 6529

In the UML meta-model, there are meta-elements called Class and Property. An instance of a Class meta-element (e.g., called Figure) may own instances of a Property meta-element. Each instance of a Property meta-element has a type (e.g., Image and Figure). Both of the instances of the Property meta-element in your model are unnamed, which, unfortunately, makes it difficult to refer to them. Nonetheless, all of the instances of the Property meta-element that an instance of the Class meta-element owns are ordered. When you create a property in a UML tool, you generally add it to the end of an ordered list.

In your diagram there are two unnamed properties that are already ordered (implicitly, based on which you created first in the tool). This order can be seen and changed in a UML compliant tool. Here is an example UML model:

enter image description here

I strongly recommend you name all your properties, as I have done in my example model. For example, I named them title and image, starting with a lower-case letter. Among other benefits, that way you can see which is which more easily when you reorder them.

Here is a specification window in a professional tool called MagicDraw, where you can drag properties into the order you like:

enter image description here

You could change the order to say that the image comes before the title.

P.S., in an analysis model, if this ordering is a rule that's important in the problem domain, I would actually show an explicit association between Image and Title having association ends called something like comes before and comes after.

Upvotes: 1

Related Questions