简体   繁体   中英

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

but should it be this:

+calculatePackagesNeeded(double, double):double

In principle

According to the UML specs:

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.

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. Nevertheless, if we assume a language-specific UML profile for java, and if we tolerate the paramter name hiding it could indeed be:

+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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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