Template method in uml

此生再无相见时 提交于 2020-01-04 03:12:07

问题


Is there any way to display template method in UML (I mean a c++ template method, not pattern)? I've found template classes only.

Suppose i have

class A {
  public:
    template <typename T>
    std::vector<T> func(T& var);
};

So, the only way I can display it in uml now is +func(in var : T&) : std::vector<T>. Is there any way to say it's template, and T is not a usual type?


回答1:


I'm not entirely sure here, but I think the answer is no.

If I understand it correctly, UML can only deal with templates on a class level -- meaning that your class A would need to be specified as a template class in order for func() to be valid.

Put another way, UML does not allow template parameters to be introduced in an operation without also being specified in the class signature. I think.

Bear in mind always that UML is not a programming language and in fact tends to break down when confronted with non-trivial source code constructs in any particular language.

More information here.




回答2:


I think this link shows what you are looking for.

Template on UML diagram




回答3:


I've been forced to represent them as individual templated function objects. This is only for the purpose of representation and modelling though.

So

template<typename T> void foo (T& t) { ... }

is modelled as:

template<typename T> class foo
{
    void operator() (T& t) { ... }
}

Its a hack.



来源:https://stackoverflow.com/questions/29491771/template-method-in-uml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!