74

How would you create an uml class diagram for constructors with parameters?

For default constructors (no parameters) you do

  • policyholder() for the diagram and in the pseudo-code

For constructors with parameters would you do the same thing:

  • policyholder (policynumber, service class, and customer age) for class diagrams and pseudo-code.

It also asked to initialize each attribute to value where an object of this type can be instantiated. If a policy number is not between 1000 and 999 inclusive, then set the policy number to 0. (policy number is attribute)

Christophe
  • 68,716
  • 7
  • 72
  • 138
blake
  • 771
  • 1
  • 6
  • 9

1 Answers1

128

The common way is to write constructors like methods and simply omit the return type.

enter image description here

If you want to be extra clear, you can add <<constructor>> in front.

magnattic
  • 12,638
  • 13
  • 62
  • 115
  • 33
    UML can be sometimes a nitpickers dream, I found out that it's actually `<>`, see [UML 2.5.1](https://www.omg.org/spec/UML/2.5.1/PDF) page 198 (PDF-page number 240) – Ciantic Oct 21 '18 at 20:56
  • 10
    @Ciantic The page numbering is still right, but the document moved to https://www.omg.org/spec/UML/2.5.1/PDF Thanks for your comment! – Clément Mar 20 '19 at 16:28
  • 1
    Page 195/745 now :) – NickW Apr 03 '23 at 11:51