简体   繁体   中英

How to represent the composion relationship for class template when drawing class diagram?

As per this answer , class template could be represented like this:

___________:  T  :
|          :.....:
|              |
|  ClassName   |
|              |
|______________|

Then how to represent the composition relationship with class template?

For example, given

template <typename T>
class FooRes
{
public:
     T  res;
     bool valid;
};

,how to represent the relationship with the classes below?

class Demo
{
    public:
       int height;
       int width;
       int area;
};

class MultiRes
{
private:
     FooRes<Demo>   res1;
     FooRes<int>    res2;
     FooRes<double> res3;
};

I think a class diagram for the said example could make it clear enough.

Could somebody shed some light on this matter?

In this answer to your other question , I developed the different ways to represent templated classes and their instantiation. You could use any of them for MultiRes , except that you would have several instantiations of a template instead of a single one.

You could use a similar technique here, but brought to the next level of compactness:

  • First, you'll model the template class FooRes with parameter T and show how it related to this abstract T .
  • Then, once the template well defined, you could use it in other diagrams either with direct bindings, or even as bound properties of MultiRes

The first would facilitate showing the links to the types used as template parameter. It would look like:

在此处输入图像描述

The second would look much more compact:

在此处输入图像描述

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