绘制类图时,如何表示类模板的组合关系?

发布于 2025-01-23 02:07:38 字数 680 浏览 2 评论 0原文

按照这个答案,可以像这样表示类模板:

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

那么如何代表与类模板的组成关系?

例如,给定

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

,如何表示与以下类别的关系?

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

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

我认为上述示例的课程图可以表明它足够清楚。

有人可以阐明这件事吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

靖瑶 2025-01-30 02:07:38

对您的其他问题的答案,我开发了代表模板类及其实例的不同方法。您可以将其中的任何一个用于Multires,除非您将对模板而不是单个模板进行几个实例化。

您可以在此处使用类似的技术,但是将其提升到了新的紧凑级:

  • 首先,使用参数 t the Template类fooors此抽象t
  • 然后,一旦模板定义了,您可以在其他图中使用它的直接绑定,甚至可以用作Multires的界属性,

第一个将有助于将链接显示为用于模板参数的类型。看起来像:

“在此处输入图像描述”

第二个看起来更紧凑:

“在此处输入图像说明”

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:

enter image description here

The second would look much more compact:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文