[英]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:您可以在这里使用类似的技术,但将其提升到一个新的层次:
FooRes
with parameter T
and show how it related to this abstract T
.T
model 模板 class FooRes
并显示它与此抽象T
的关系。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.