简体   繁体   English

绘制class图时如何表示class模板的组成关系?

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

As per this answer , class template could be represented like this:根据这个答案,class 模板可以这样表示:

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

Then how to represent the composition relationship with class template?那么如何用class模板表示组成关系呢?

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.我认为上述示例的 class 图可以使它足够清楚。

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.您可以将它们中的任何一个用于MultiRes ,除了您将有多个模板实例化而不是单个实例化。

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 .首先,您将使用参数T model 模板 class FooRes并显示它与此抽象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然后,一旦模板定义好,您就可以在其他图表中使用它,直接绑定,甚至作为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:第二个看起来更紧凑:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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