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 |
| |
|______________|
Define the Classifier for the Template, and include the properties and methods from the template, then instead of using the standard class notation, use the Classifier you have created for each Class that uses the template. This would be correct usage of the UML for Templates.
Deriving from a non-template base class There is no requirement that your base class be a template. It is quite possible to have a template class inherit from a 'normal' class. This mechanism is recommended if your template class has a lot of non-template attributes and operations.
Specifically, Area is not a template class, but a class template. That is, it is a template from which classes can be generated. Area<int> is such a class (it's not an object, but of course you can create an object from that class in the same ways you can create objects from any other class).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With