简体   繁体   English

在 UML 类图中为 C++ 类添加构造函数和析构函数

[英]Adding constructors and destructors in a UML class diagram for C++ classes

在为C++代码编写UML类图时,是否需要包含相关类的构造函数和析构函数?

In many cases, adding constructors/destructors to a C++ class diagram would just be textual boilerplate noise and not really meaningful.在许多情况下,向 C++ 类图中添加构造函数/析构函数只是文本样板噪音,并没有真正意义。 Only if you want your diagram to be a complete documentation of your C++ classes, you may want to add constructors.只有当您希望图表成为 C++ 类的完整文档时,您才可能需要添加构造函数。

Contrary to what @Marco is saying below, this is not a matter of the underlying business logic, but a purely ergonomic issue of avoiding cluttering and noise in (typically complex) diagrams.与@Marco 在下面所说的相反,这不是底层业务逻辑的问题,而是避免(通常是复杂的)图表中的混乱和噪音的纯粹符合人体工程学的问题。

The constructor can be added if it's part of the business logic, you just don't add a return type.如果构造函数是业务逻辑的一部分,则可以添加它,您只是不添加返回类型。
Would be under the functions/methods section:将在功能/方法部分下:
+ClassName() +类名()
I would not add destructors.我不会添加析构函数。 Again, depends on whether your business logic needs it.同样,取决于您的业务逻辑是否需要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM