创建UML图时应该编写构造函数吗?

When creating UML diagram should the constructors be written?

我的作业要求我为实际的 Java 程序创建 UML 图。 但是程序中有几个构造方法,我很困惑。 我是否应该将这些构造函数方法添加到图表中?

根据 UML 规范(2.5 版的第 11.4.4 节):

A constructor is an Operation having a single return result parameter of the type of the owning Class, and marked with the standard stereotype «Create».

如果您正在创建图表来记录代码,您应该包括所有显式构造函数。

如果您正在构建一个专注于功能的模型,那么通常会省略构造函数。但是你的详细程度完全不同。