Book a Demo

Author Topic: What is the best way to model multiple constructor  (Read 4123 times)

dsargrad

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
What is the best way to model multiple constructor
« on: April 10, 2009, 10:24:45 pm »
I have a class that has two different constructors. I tried to create a sequence diagram that shows (with an alt fragment) the two different modes of construction. This did not work (cant create two "new" messages) within a single sequence for that class.

Is there a better way to model this?

Martin Terreni

  • EA User
  • **
  • Posts: 672
  • Karma: +0/-0
  • Sorry, I can't write
    • View Profile
Re: What is the best way to model multiple constru
« Reply #1 on: April 10, 2009, 10:36:18 pm »
If you trying to do overloading the right way would be to create two different diagrams, since these are two different methiods.
Recursion definition:
If you don’t understand the definition read "Recursion definition".

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: What is the best way to model multiple constru
« Reply #2 on: April 10, 2009, 11:15:00 pm »
Hmm, I guessing you wish to model the behaviour of a user of the class, one time calling the one constructor, and in the other alternative the other constructor.
If you then just drag your class onto the sequence diagram it will create a class, and not an instance of your class. You can only have class representation on your diagram, but you can have as many instances as you like.
So make sure that you create two instances of your class on the sequence diagram and call their constructor with the "new" message.

dsargrad

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: What is the best way to model multiple constru
« Reply #3 on: April 10, 2009, 11:49:29 pm »
I see. That makes sense. Thank you.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: What is the best way to model multiple constru
« Reply #4 on: April 10, 2009, 11:59:57 pm »
This also depends on what you are trying to indicate. Perhaps your caller simply acquires the two instances for its own use (or to pass on to others). You might see something like two calls to a shared (factory) method or shared constructor of the class, each of which returns an instance as its return value. In this case you'd see the (target) class once, with multiple calls to the factory method or constructor, each of which returns an instance. You could optionally annotate the calls to show which arguments were provided by each; EA can help you do this (though it might have to be diagram wide rather than message specific).
No, you can't have it!