Mat Kelly
Mat Kelly

Reputation: 2362

Representing overloaded methods in UML

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.

Upvotes: 10

Views: 17221

Answers (5)

Gabriel Ščerbák
Gabriel Ščerbák

Reputation: 18570

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.

Upvotes: 6

Ted Johnson
Ted Johnson

Reputation: 4343

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.

Upvotes: 0

Vincent Ramdhanie
Vincent Ramdhanie

Reputation: 103145

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.

Upvotes: 4

alepuzio
alepuzio

Reputation: 1418

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;

Upvotes: 4

Brian Matthews
Brian Matthews

Reputation: 8596

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.

Upvotes: 2

Related Questions