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).
-
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– Doc Brown2020年12月18日 17:50:40 +00:00Commented 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.Felix Jönsson– Felix Jönsson2020年12月18日 17:59:24 +00:00Commented Dec 18, 2020 at 17:59
-
2It would confuse me. Also, I’d be annoyed that xywh were not rolled together into a single rectangle regardless of UML. See introduce parameter objectcandied_orange– candied_orange2020年12月18日 18:17:56 +00:00Commented 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.Greg Burghardt– Greg Burghardt2020年12月18日 21:09:47 +00:00Commented Dec 18, 2020 at 21:09
-
1Your 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– Christophe2020年12月19日 02:38:25 +00:00Commented Dec 19, 2020 at 2:38
1 Answer 1
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.
-
3Also, 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.candied_orange– candied_orange2020年12月18日 18:23:18 +00:00Commented Dec 18, 2020 at 18:23
-
1Section 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– Christophe2020年12月19日 02:23:58 +00:00Commented Dec 19, 2020 at 2:23