7

Using UML, how can I represent A< Foo > in the following code?

template< class T > 
class A : public T
{
    /* ... */
};

class Foo { };

A< Foo > a_foo;

Something like this (apologies for the poor ascii art... and to Jon Skeet) is my first guess, but I suspect it is not correct.

            ________________
            |              |
            |              |
            |     Foo      |
            |              |
            |______________|
             /:\  /|\
«bind»(Foo)   :    |
              :    |   .......               
            __:____|___:  T  :
            |          :.....:
            |              |
            |      A       |
            |              |
            |______________|
Community
  • 1
  • 1
PaulH
  • 7,759
  • 8
  • 66
  • 143
  • Doesn't the CRTP describe a class inheriting from a template class, where the inheritor passes itself as template parameter? In this case the generalization link should have the opposite direction. The bind dependency shown is correct IMHO. – πάντα ῥεῖ Jul 12 '12 at 14:09
  • @g-makulik - you're correct (as Luchiane pointed out below). I've modified the title. – PaulH Jul 12 '12 at 14:12
  • @Luc Touraille - good title. :) – PaulH Jul 12 '12 at 21:43

2 Answers2

2

There is a proposal, by the U.M.L. designers, but, its not part of the standard, yet.

If, there wasn't any template parameters, the object "a" of type "A", may be like this:

+--------------------+
|        a: A        | 
+--------------------+
| [+] doSomething(); |
+--------------------+

The object "a", who is a template of "a", with the type parameter "Foo", may be represented like this:

                  +-----+
+-----------------| Foo |
|                 +-----+
|        a: A        | 
+--------------------+
| [+] doSomething(); |
+--------------------+

Note, that, in U.M.L., when you declare a class, they are represented by a rectangle, while specific objects, such "a", are represented by rectangle with round corners. Some people, & tools, doesn't follow the "round corners" specification.

Cheers.

umlcat
  • 4,091
  • 3
  • 19
  • 29
  • So there is no standard way to represent this relationship today? Also, I'm curious, do you have a particular tool you like to use for UML? I'm using MS Visio right now and I'm by no means married to it. – PaulH Jul 12 '12 at 21:39
  • @PaulH: No, I don't have a particular tool. I started with Rational Rose (UML Authors tools), Umbrello, & other tools, but, ended using Power Point, Visio & Libre Office Draw ( Open Source Version of Visio), because of limitations, not money or tools :-s – umlcat Jul 13 '12 at 14:33
  • Personally I use the VisualParadigm Community (free and cross-platform) which is quite decent. – Adrian Maire Jul 26 '19 at 07:06
2

I am not quite sure if this is perfectly standard but this is the definition of your "A" class when I tried to reverse engineer it using Enterprise Architect:

      +---------+
+-----| T:class |
|     +---------+
|        T |
|   A      |
+----------+
|          |
+----------+

just add the name of the template parameter as the parent name of the class.

babdrabbo
  • 53
  • 4