I have a homework that requires me to create a UML diagram for an actual Java program. But there are several constructors methods in the program and I'm confused. Should I add these constructors methods to the diagram or not?
Asked
Active
Viewed 4,723 times
1 Answers
6
As per UML specification (section 11.4.4 of version 2.5):
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».
If you're creating a diagram to document a code you should include all explicit constructors.
If you're building a model focusing on functionality constructors are typically omitted. But then your level of details is entirely different.

Ister
- 5,958
- 17
- 26
-
2I think you also want to select isStatic=true, to make obvious that the constructor can be called without already having an instance. (Which would be absurd.) – Jim L. Mar 31 '19 at 12:59
-
Actually `isStatic=true` is not necessary, since the UML separates the creation of an Object and its initialization with a constructor. The `CreateObjectAction` creates an empty Object and the `«create»-operation` then has to fill in all the default values, satisfy the post condition and invariants and start its classifier Behavior (if applicable). Of course, if you want to describe a Java-program it makes sense to adopt the Java conventions. – Axel Scheithauer Apr 10 '19 at 07:34