绘制类图时,如何表示类模板的组合关系?
按照这个答案,可以像这样表示类模板:
___________: 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在对您的其他问题的答案,我开发了代表模板类及其实例的不同方法。您可以将其中的任何一个用于
Multires
,除非您将对模板而不是单个模板进行几个实例化。您可以在此处使用类似的技术,但是将其提升到了新的紧凑级:
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:
FooRes
with parameterT
and show how it related to this abstractT
.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: