简体   繁体   English

带参数的Java方法的类图

[英]Class diagram for Java method with parameters

I have a class with the method below.我有一个使用以下方法的课程。 What is the correct way to write the method and its parameters in a Class Diagram?在类图中编写方法及其参数的正确方法是什么?

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

I'm currently using this:我目前正在使用这个:

+calculatePackagesNeeded():double +calculatePackagesNeeded():double

but should it be this:但应该是这样的:

+calculatePackagesNeeded(double, double):double +calculatePackagesNeeded(double, double):double

In principle原则上

According to the UML specs:根据 UML 规范:

An Operation is a BehaviorialFeature of an Interface, DataType, or Class.操作是接口、数据类型或类的行为特征。 An Operation may be directly invoked on instances of its featuringClassifiers.可以在其 featuresClassifier 的实例上直接调用 Operation。 The Operation specifies the name, type, Parameters , and Constraints for such invocations. Operation 为此类调用指定名称、类型、参数和约束。

Going by the book, it should be:按照书上的说法,应该是:

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

because the primitive UML types are limited to Integer , Boolean , String , UnlimitedNatural , and Real and the parameter names is not optional.因为原始 UML 类型仅限于IntegerBooleanStringUnlimitedNaturalReal并且参数名称不是可选的。 Nevertheless, if we assume a language-specific UML profile for java, and if we tolerate the paramter name hiding it could indeed be:然而,如果我们假设 Java 有一个特定于语言的 UML 配置文件,并且如果我们容忍隐藏的参数名称,它确实可能是:

+calculatePackagesNeeded(double, double):double

In practice在实践中

However, for high-level models, you do not necessarily need this level of details.但是,对于高级模型,您不一定需要这种级别的细节。 Also, in early stages of any OO modeling, operations and responsibilities may be identified for classes, before the details of the parameters are worked out.此外,在任何 OO 建模的早期阶段,在制定参数的细节之前,可以为类确定操作和职责。 In these contexts you may well use:在这些情况下,您可以很好地使用:

+calculatePackagesNeeded():double

This simplification seems however acceptable imho, only if the other operations (at least of the same class) are shown this way too, because as soon as you'd have some real signatures in the model, the shortcut notation could create ambiguity.然而,这种简化似乎是可以接受的,恕我直言,只有当其他操作(至少是同一类)也以这种方式显示时,因为一旦您在模型中有一些真实的签名,快捷符号可能会产生歧义。

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

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