Representation of overloaded methods in UML

I am trying to create a UML diagram representing some Java code.

In the class, I have a method that is overloaded.

As far as I know, parameters for methods are not shown in UML diagrams.

How can I imagine method overloading in UML?

Thanks.

+6
java method-overloading uml
source share
5 answers

The subclass defines the method with the same signature as the method you want to override, and add a note {redefines} to the method. For example:

+doSomething(p:AThing):int{redefines} 

This means that the doSomething () method overrides the method in the superclass. And yes, the parameters for the methods are shown in the diagrams. As in the example, p is an AThing type parameter.

+3
source share

Speaking of overloading - for example, in your class you have more methods with the same name but with a different signature (parameters, perhaps the return value depending on the address language ...), you should provide a signature. UML does not indicate that you cannot have method parameters.

+3
source share

Check the display options for the entire chart or individual class / interface. Most UML tools have display options showing a list of method parameters.

+2
source share

You don't say your tool and UML diagram (I think the diagram class), but you have 2 ways:

  • You can write a note about this method;
  • You can use the stereotype keyword that spells <overloaded β†’ in this method;
+2
source share

Most of the answers above are correct given a specific question. Alepucio, Vincent and bmatthews68 have answers that make sense in context.

** If the question is about overriding the superclass method with the same signature as overriding, this is the correct definition. If it is overloaded with the fact that you create the same method that takes different arguments, then I don’t think that this can be modeled structurally, you can show it using a sequence diagram, for example, a behavioral one, but not really.

So + doSomething (p: AThing): int {redefines} is correct, as Vincent did.

** If your problem / question concerns parameters that do not appear visually on the chart, which is usually a parameter in most UML tools.

** If you want to make it even clearer what you are doing, use the <> keyword, also note that the keyword is not a stereotype, as it is not part of the metamodel.

0
source share

All Articles