Class 带参数的 Java 方法图

Class diagram for Java method with parameters

我有一个 class 用下面的方法。在 Class 图表中编写方法及其参数的正确方法是什么?

public class Staff {
    public double calculatePackagesNeeded(double strippingNeeded, double strippingLength) {
        return (double)Math.ceil(strippingNeeded / strippingLength);
    }
}

我目前正在使用这个:

+calculatePackagesNeeded():double

但应该是这样的:

+calculatePackagesNeeded(双倍,双倍):双倍

原则上

根据 UML 规范:

An Operation is a BehaviorialFeature of an Interface, DataType, or Class. An Operation may be directly invoked on instances of its featuringClassifiers. The Operation specifies the name, type, Parameters, and Constraints for such invocations.

按照书上的说法,应该是:

+calculatePackagesNeeded(strippingNeeded : Real, strippingLength :Real):Real

因为原始 UML 类型仅限于 IntegerBooleanStringUnlimitedNaturalReal,并且参数名称不是可选的.然而,如果我们为 java 假设一个特定于语言的 UML 配置文件,并且如果我们容忍隐藏参数名称,它确实可以是:

+calculatePackagesNeeded(double, double):double

在实践中

但是,对于高级模型,您不一定需要这种级别的详细信息。此外,在任何 OO 建模的早期阶段,在确定参数的细节之前,可以确定 classes 的操作和责任。在这些情况下,您可以使用:

+calculatePackagesNeeded():double

这种简化似乎是可以接受的恕我直言,只有当其他操作(至少相同 class)也以这种方式显示时,因为只要您在模型中有一些真实的签名,快捷符号可能会产生歧义。