Curiously recurring 模板模式的 UML 图
UML diagram for the Curiously recurring template pattern
如何在不为每个继承的 class 复制基础 class 的情况下正确绘制 C++ Curiously recurring template pattern (CRTP) 的 UML 图,即以一种反映实现而不是比编译后的情况?
问题归结为to:what如果模板参数可以是一整套派生的任何一个,我是否写入公共模板库的虚线框classclass是吗?
如另一个答案所述,C++ Curiously recurring template pattern (CRTP) 的示例是:
template <class T>
class Base
{
// methods within Base can use template to access members of Derived
};
class Derived : public Base<Derived>
{
// ...
};
what do I write into the dashed box of the common template-baseclass if the template parameter can be any of a whole set of derived classes?
模板的虚线框 class 显示模板参数,如果是 class Base :
事实上模板参数可以是一整套派生classes中的任何一个是不相关的,因为它可以是其他任何东西。
在图中添加派生的 class 以获得完整的 CRTP:
根据您的评论:
that doesn't answer my question; the case that the template parameter must be a derived class isn't mentioned at all.
在你的问题中你只是说它可以是,现在你想要它必须是。
注意 CRTP 由 two classes 定义,而不仅仅是由基 class 定义。无论如何,如果你想对模板参数 (T) 进行限制,只需使用一个约束,可能是 T.parents->includes(Base) 即使我不确定在其中使用 T,它必须应用于 T 而不是 T 的值本身就是一个 class
从你的评论到我的回答:
Another idea: would it be allowed to draw a collaboration connector from the base-classes T in the dashed box down to every depicted class that is derived from base?
我看不出在那种情况下如何出现协作,您是否考虑过依赖关系?
对我来说,你无法从虚线框中的T中得出关系,甚至有可能不表示你想要什么。
与其绘制从 T 到派生的 classes 的关系,不如在每次继承和绑定时绘制派生的 classes,这是 UML 中的正确方法。
如何在不为每个继承的 class 复制基础 class 的情况下正确绘制 C++ Curiously recurring template pattern (CRTP) 的 UML 图,即以一种反映实现而不是比编译后的情况?
问题归结为to:what如果模板参数可以是一整套派生的任何一个,我是否写入公共模板库的虚线框classclass是吗?
如另一个答案所述,C++ Curiously recurring template pattern (CRTP) 的示例是:
template <class T>
class Base
{
// methods within Base can use template to access members of Derived
};
class Derived : public Base<Derived>
{
// ...
};
what do I write into the dashed box of the common template-baseclass if the template parameter can be any of a whole set of derived classes?
模板的虚线框 class 显示模板参数,如果是 class Base :
事实上模板参数可以是一整套派生classes中的任何一个是不相关的,因为它可以是其他任何东西。
在图中添加派生的 class 以获得完整的 CRTP:
根据您的评论:
that doesn't answer my question; the case that the template parameter must be a derived class isn't mentioned at all.
在你的问题中你只是说它可以是,现在你想要它必须是。
注意 CRTP 由 two classes 定义,而不仅仅是由基 class 定义。无论如何,如果你想对模板参数 (T) 进行限制,只需使用一个约束,可能是 T.parents->includes(Base) 即使我不确定在其中使用 T,它必须应用于 T 而不是 T 的值本身就是一个 class
从你的评论到我的回答:
Another idea: would it be allowed to draw a collaboration connector from the base-classes T in the dashed box down to every depicted class that is derived from base?
我看不出在那种情况下如何出现协作,您是否考虑过依赖关系?
对我来说,你无法从虚线框中的T中得出关系,甚至有可能不表示你想要什么。
与其绘制从 T 到派生的 classes 的关系,不如在每次继承和绑定时绘制派生的 classes,这是 UML 中的正确方法。