I am attempting to create a UML diagram representative of some Java code.
In a class I have a method that is overloaded.
As far as I know, parameters for methods aren't shown in UML diagrams.
How do I represent method overloading in UML?
Thanks.
In Java, two or more methods may have the same name if they differ in parameters (different number of parameters, different types of parameters, or both). These methods are called overloaded methods and this feature is called method overloading. For example: void func() { ... }
Switch to Operations tab and select the operation from superclass (indicated in Classifier column) which you wish to override. Press the Override button and you will see the Classifier of the operation changed form superclass to subclass. Now the method is being overridden and show in the subclass.
The compiler distinguishes overloaded methods by their signatures—a combination of the method's name and the number, types and order of its parameters, but not its return type. If the compiler looked only at method names during compilation, the code in Fig.
Usually, method overloading happens inside a single class, but a method can also be treated as overloaded in the subclass of that class — because the subclass inherits one version of the method from the parent class and then can have another overloaded version in its class definition.
In the sub class you specify the method with the same signature as the method you wish to override and add a note {redefines} to the method. For example:
+doSomething(p:AThing):int{redefines}
This implies that doSomething() method overrides the method in a super class. And yes, parameters for methods are shown on diagrams. As in the example p is a paremeter of type AThing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With