views:

650

answers:

5

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.

+1  A: 

Check the display options for the entire diagram or the individual class/interface. Most UML tools have options to display show the parameter list of methods.

bmatthews68
+1  A: 

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.

Vincent Ramdhanie
+1, but you might like to correct the spelling of {redifines} -> {redefines}
chimp
Overloading is not the same as redefining. There may be no base class at all (other than Object), but the class could have foo(int):int and foo(double):double.
James A. Rosen
A: 

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

  1. you can write a note about this method;
  2. you can use keyword stereotype writing <<overloaded>> in this method;
alepuzio
A: 

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

** If the question is around Overriding of a super classes method with the same signature than redefining is the correct definition. If it is overloading in that you create the same method which takes different arguments then I do not believe this is possible to model structurally, you can show this with a sequence diagram for example which is behavioral, but still not really.

So +doSomething(p:AThing):int{redefines} is correct which is what Vincent put.

** If your problem/question is just around parameters not showing up visually in a diagram that is usually a setting in most UML tools.

** If you want to make it even more clear what you are doing then use a keyword <>, also note a keyword is not a stereotype as it is not part of the meta-model.

Ted Johnson
A: 

When talking about overloading - e.g. in your class you have more methods with same name but different signature(parameters, maybe return value depending on target language...), you should provide the signature. UML doesn't specify that you cannot have method parameters.

Gabriel Ščerbák