简体   繁体   中英

Representation array of arrays on UML diagram

How can I represent a pointer to an array of pointers to other arrays (as a matrix) on UML Diagram?

class C
{
  int Matrix[3][3];
  ...
}

Indeed, to elaborate somewhat on what qwerty_so and Bruno already answered, the standard UML data types are very limited and a properties can have at most one-dimensional multiplicity.

For programming-language specific types we usually include (often implicitly) a profile to extend the meta-model with additional data types. This is ok for the missing types and template-type . But unfortunately, it doesn't really work for transforming multiplicities into array dimensions.

Here two options:

  1. Be pragmatic: just assume that you can use the C++ type system in your UML via an hypothetical profile.

    • Advantage: Concise notation; Most people will understand what you mean.
    • Inconvenience: Not compliant to the specs: If you must contractually deliver a compliant model, you'd better look at the next option.
  2. Be legit : abstract your design further and do not get caught by your own implementation decision. The matrix shall then no longer be a two dimensional array, but a ditionary/map that maps a pair of coordinates to an integer. This is done in UML with a qualified association . In this understanding, the dimensions of the array would be expressed as constraints on the qualifier.

    • Advantage: fully compliant; expressive; a more powerful design, since it would not force you to use multi-dimensional arrays, but would allow you to use as well a sparse matrix implemented with a std::map<std::pair<size_t,size_t>,int>
    • Inconvenience: less intuitive to read

From a graphical point of view, it could probably look like one of the following:

在此处输入图像描述

Some thoughts

UML basically is language agnostic. And multi-dimensional arrays are just language specific by a) having a notation at all and b) in which syntax. To stay on the safe side you should not show such details.

Anyhow, sometimes you have the need to show them. If so, you need to know that your model is no longer that independent of implementation details as it should be. A modeler usually translates business needs into a formalism a coder can understand. And the coder just knows how to implement these details. Trust your coder, don't take him/her on the short line. If you can't trust them you're doomed anyway.


Having said the above and you still want to show the array as 2-dimensional you could do it like this:

在此处输入图像描述

UML itself does not support the notation (only collections being 1-dimensional). But if it for any reason helps you and the coders I would not mind.

Whether or not the above is supported by an UML tool depends. Using EA I needed to define the datatype to be int[3] and the multiplicity being set to 3 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM