Author Topic: [Sequence Diagram] Setting an object to another object  (Read 2118 times)

jepessen

  • EA User
  • **
  • Posts: 61
  • Karma: +1/-0
    • View Profile
[Sequence Diagram] Setting an object to another object
« on: June 28, 2016, 08:33:13 pm »
This is my situation:

  • I've a Sink class in which I can set some property
  • I've a static Configuration class. This class has a method addSink that takes a Sink as argument and deep-copy it inside the class instance.

I want to create a sequence diagram in which I set an instance of Sink (named ConsoleSink) and then pass it as argument of my Configuration class instance.

This is what I've done:



I don't know if I'm doing it correctly. I want to show in Sequence digram first that I create and set the Sink class instance, and then I pass it as argument in Configuration class instance.

This is the correct way to do it?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7752
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: [Sequence Diagram] Setting an object to another object
« Reply #1 on: June 28, 2016, 08:43:34 pm »
No, you should drag your classes onto the diagram as lifelines, and name them (now the lifelines are unnamed isntances of classes that might not exist)

Also don't use the «create» stereotype, but set the lifecycle property to New in your message.
and using an Actor call Program is also not what I would do.

I have documented some of my best practices regarding sequence diagrams here: UML Best Practice: One Operation => One Sequence Diagram

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 8972
  • Karma: +136/-124
  • I'm no guru at all
    • View Profile
Re: [Sequence Diagram] Setting an object to another object
« Reply #2 on: June 28, 2016, 08:48:08 pm »
To me that looks ok. I would not use a <<create>> but rather set the Lifecycle to New in the properties of the first message. (Oh, I see that Geert mentioned that already)

q.

jepessen

  • EA User
  • **
  • Posts: 61
  • Karma: +1/-0
    • View Profile
Re: [Sequence Diagram] Setting an object to another object
« Reply #3 on: June 28, 2016, 09:09:45 pm »
Ok I've set the lifecycle property and set lifelines (they were already lifelines, but unnamed).

Now this is the diagram:



I don't know if it's correct that the lifeline if the Sink objects ends before I set it to Configuration instance. I've tried to increase the length if ConsoleSink lifeline but with no result. What I should do now?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7752
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: [Sequence Diagram] Setting an object to another object
« Reply #4 on: June 28, 2016, 09:29:23 pm »
There 's an option somewhere that controls the automatic "destruction"of objects.

Still seems weird to me that you would call the constructor Sink() on a class ConsoleSink(). Isn't the constructor supposed to have the same name as the class? (in most programming languages I know)

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 8972
  • Karma: +136/-124
  • I'm no guru at all
    • View Profile
Re: [Sequence Diagram] Setting an object to another object
« Reply #5 on: June 28, 2016, 10:54:57 pm »
Tools/Options/Diagram/Sequence/Garbage... (right middle)

Heaven knows where this in the ribbons.

q.

jepessen

  • EA User
  • **
  • Posts: 61
  • Karma: +1/-0
    • View Profile
Re: [Sequence Diagram] Setting an object to another object
« Reply #6 on: June 28, 2016, 11:12:02 pm »
I've found the garbage option and it's enabled, so with this option active I obtain the last diagram.

jepessen

  • EA User
  • **
  • Posts: 61
  • Karma: +1/-0
    • View Profile
Re: [Sequence Diagram] Setting an object to another object
« Reply #7 on: June 28, 2016, 11:16:01 pm »
I've disabled the GarbageCollect (autodelete) option and now this is the diagram (I've also fixed the name of the object passed to Configuration instance):



It's correct now or there's something else that I must fix?

qwerty

  • EA Guru
  • *****
  • Posts: 8972
  • Karma: +136/-124
  • I'm no guru at all
    • View Profile
Re: [Sequence Diagram] Setting an object to another object
« Reply #8 on: June 28, 2016, 11:33:23 pm »
Just remove the name from the New method call. So it is explicit.

q.

jepessen

  • EA User
  • **
  • Posts: 61
  • Karma: +1/-0
    • View Profile
Re: [Sequence Diagram] Setting an object to another object
« Reply #9 on: June 28, 2016, 11:40:48 pm »
But in the constructor (ok, the name is wrong) I put an ID, there's not a default constructor. Can I omit it in UML logic?

qwerty

  • EA Guru
  • *****
  • Posts: 8972
  • Karma: +136/-124
  • I'm no guru at all
    • View Profile
Re: [Sequence Diagram] Setting an object to another object
« Reply #10 on: June 29, 2016, 01:40:52 am »
Just leave the name empty. Since it is a constructor call, it is implicit.

q.

jepessen

  • EA User
  • **
  • Posts: 61
  • Karma: +1/-0
    • View Profile
Re: [Sequence Diagram] Setting an object to another object
« Reply #11 on: June 29, 2016, 01:49:20 am »
Ok thanks.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1073
  • Karma: +81/-5
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: [Sequence Diagram] Setting an object to another object
« Reply #12 on: August 22, 2016, 08:26:18 pm »
This question is not related to the original post. Please delete it and repost in its own thread.

/Uffe
My theories are always correct, just apply them to the right reality.

qwerty

  • EA Guru
  • *****
  • Posts: 8972
  • Karma: +136/-124
  • I'm no guru at all
    • View Profile
Re: [Sequence Diagram] Setting an object to another object
« Reply #13 on: August 22, 2016, 08:52:00 pm »
Hehe. We're not on SO here xD

q.

bockfu

  • EA User
  • **
  • Posts: 55
  • Karma: +4/-1
    • View Profile
Re: [Sequence Diagram] Setting an object to another object
« Reply #14 on: August 28, 2016, 05:44:25 am »
I encourage you to consider updating the diagram based on Geerts blog post and generalize the trigger/calling behavior by using a gate.  I've applied this practice and find it useful.   This is one thing I encourage you to get familiar with, the earlier the better.

I also get the impression the operations for the class are not defined.    Since it appears The lower level details are valuable, you may want to consider stubbing out the class. This way the operation names will become available in a drop down menu when making call associations across lifelines.  I think this would help align the diagram with the specific behavior, automate the alignment between the class definition and diagram, and ultimately help you narrow in on a model definition that makes the most sense.

Just my thoughts.