1

I have the following constructor in a class for a code I'm writing an assignment on for school:

public Plant(int xPos, int yPos,int width,int height, int hp,String imageLocation,String audioLocation,Stage stage)

The only parameter I find valuable to show in the UML diagram I'm creating is Stage. Could the other parameters be omitted then? This is the only constructor in the class so there is no chance of confusion in regard to that. Though, I suppose one could get confused to not find the method when searching through the actual code later on?

Edit: I'm interested in the advice of UML practitioners using UML diagrams outside of university, and not opinions on what could please my teacher (see comments).

7
  • The idea of UML is to provide a more abstract (=simplified) representation of software than code. But the right amount of simplification depends heavily on the context. For your school assignment, you will have to ask your teachers what they think, not some strangers in the internet.
    – Doc Brown
    Commented Dec 18, 2020 at 17:50
  • Well I want to know what the general opinion is as well and don't simply only care about getting my assignment "right" per the teachers standard. Commented Dec 18, 2020 at 17:59
  • 2
    It would confuse me. Also, I’d be annoyed that xywh were not rolled together into a single rectangle regardless of UML. See introduce parameter object Commented Dec 18, 2020 at 18:17
  • 1
    @candied_orange - in the very least a Point to represent the x,y coordinates, and maybe a Dimension to represent the width and height. If it is annoying to write in a UML diagram, it is likely annoying to write in plain code as well. Commented Dec 18, 2020 at 21:09
  • 1
    Your question is relevant and can be (was) answered using objective arguments. I therefore dared to reword it slightly in order to make it more objective and avoid calling for opinions (out of scope here). I hope you can agree with the edited version.
    – Christophe
    Commented Dec 19, 2020 at 2:38

1 Answer 1

5

The only UML diagram this is likely to apply to is the Class Diagram.

In a class diagram, the constructor is treated as merely another method. It is sometimes prefixed with <<create>>, or the return type omitted, to indicate that it is a constructor; but it is a method like any other nevertheless.

In a typical UML class diagram, methods are indicated using their entire signature. I would therefore expect all of the parameters to be present, even in the constructor method.

2
  • 3
    Also, just because there is only one constructor now is no guarantee that another won’t get added later. UML gets out of sync with code quickly enough as is. It doesn’t need any extra help. Commented Dec 18, 2020 at 18:23
  • 1
    Section 11.4.4 of the UML 2.5 specs seems more assertive: "A constructor is an Operation having a single return result parameter of the type of the owning Class, and marked with the standard stereotype «Create».", but ok, in practice the target programming language heavily influences this aspect of the notation ;-)
    – Christophe
    Commented Dec 19, 2020 at 2:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.