Book a Demo

Author Topic: Reverse Engineering: Associations in class diagram  (Read 15074 times)

Eulinky

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Reverse Engineering: Associations in class diagram
« on: August 27, 2014, 05:08:39 am »
Hi, I just imported existing C# code in EA 11, it all worked smoothly, beside the classes EA generated a class diagram for each namespace containing all these classes. What I wonder is, no associations have been generated. Is there a reason why associations are not drawn? Or do I miss a checkbox? Is there somewhere a button "Show all Associations"? :)

Example: Two classes Person and Address. Person has an Address, both classes are shown, the Address Property in Person is displayed, however there is no Association drawn.

Thanks!
« Last Edit: August 27, 2014, 05:08:59 am by Eulinky »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Reverse Engineering: Associations in class dia
« Reply #1 on: August 27, 2014, 05:23:19 am »
I don't use RE but if there is no association to be seen then it's because EA did not create any on import. There is a way to hide connectors but that is likely not the case. You can verify that: Diagram/Advanced/Visible Relations.

q.

Eulinky

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Reverse Engineering: Associations in class dia
« Reply #2 on: August 27, 2014, 06:15:24 am »
Yeah, there is nothing hidden. Looks like no relations have been created. But can that be true? The mighty EA cannot create the relations between objects via reverse engineering? I truely can't believe that. I mean I have both classes on one diagram. One class has a property with type of the other and there is no way I can tell EA to draw an association between these two?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Reverse Engineering: Associations in class dia
« Reply #3 on: August 27, 2014, 08:23:20 am »
As said, I don't use RE (currently). And the last time is too long ago. There are some restriction how EA compiles the source to UML but I'm not in that matters right now. Just wait a day or so. Other can likely give you a clue.

q.

AndyJ

  • EA User
  • **
  • Posts: 337
  • Karma: +5/-3
  • It's only a model
    • View Profile
Re: Reverse Engineering: Associations in class dia
« Reply #4 on: August 27, 2014, 03:39:57 pm »
Quote
... One class has a property with type of the other and there is no way I can tell EA to draw an association between these two?

Now that's interesting.

When I "type" something, I don't draw an association between the classes. I usually just float (i.e. boxes with no associations) the type (and enumeration) classes in a reference section of the class diagram.

Should there also be an association between these things?
Sun Tzu: "If you sit by the river long enough, eventually the body of MS Visio floats past."

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Reverse Engineering: Associations in class dia
« Reply #5 on: August 27, 2014, 04:44:31 pm »
Quote
Quote
... One class has a property with type of the other and there is no way I can tell EA to draw an association between these two?

Now that's interesting.

When I "type" something, I don't draw an association between the classes. I usually just float (i.e. boxes with no associations) the type (and enumeration) classes in a reference section of the class diagram.

Should there also be an association between these things?

This isn't my area at all, but... a C# property is represented in EA by a «property» stereotyped public operation representing the getter/setter pair plus a private attribute. While it's true that EA won't create an Association from the type of an operation, it should still create the Association you want to see from the type of the private attribute. Unless you had the "Do not import private members" option ticked?
« Last Edit: August 27, 2014, 04:49:23 pm by KP »
The Sparx Team
[email protected]

Eulinky

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Reverse Engineering: Associations in class dia
« Reply #6 on: August 28, 2014, 06:46:16 am »
No, i haven't ticked that option. I tried to reproduce that behavior by excluding the Reverse engineering. Maybe my problem becomes clearer that way: I created a blank project and added two classes to the same package: Person and Address. I added an attribute (which I called property before) to Person: PrivateAddress of type Address.

Now I drag both classes on a class diagram but no association is drawn.

I remove the Address from the diagram, right click Person - Add related Item -> NO connection types are selectable so even this does not work. Looks like Reverse Engineering is not the problem.

One thing I wanna add: Visual Studio Ultimate actually does exactly that: Dropping these to classes on a diagram automatically draws an Association between them. Isn't this how you should interpret a UML association?
« Last Edit: August 28, 2014, 06:54:07 am by Eulinky »

AndyJ

  • EA User
  • **
  • Posts: 337
  • Karma: +5/-3
  • It's only a model
    • View Profile
Re: Reverse Engineering: Associations in class dia
« Reply #7 on: August 28, 2014, 08:22:27 am »
Hmm...

Under the circumstances you describe, I'd usually draw an association between the two classes and label that association as Private Address.

Or. If there's some characteristics of Private Address which don't belong in either Address or Person, I'd link the two classes with an association class.

I'm not familiar with the convention of using "type" to define those relationships.

Please bear in mind, I'm no UML expert, I'm only commenting on the conventions used here...
Sun Tzu: "If you sit by the river long enough, eventually the body of MS Visio floats past."

AndyJ

  • EA User
  • **
  • Posts: 337
  • Karma: +5/-3
  • It's only a model
    • View Profile
Re: Reverse Engineering: Associations in class dia
« Reply #8 on: August 28, 2014, 08:46:26 am »
I'd suggest that you model something like this and then see what kind of code it generates.



Note that I've used simple associations, you may want to try aggregations etc.
Sun Tzu: "If you sit by the river long enough, eventually the body of MS Visio floats past."

webfox

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Reverse Engineering: Associations in class dia
« Reply #9 on: August 28, 2014, 03:53:20 pm »
Hi,

do you use auto-properties in your C# code to represent associations between classes? If so, EA does and will not recognise auto-properties holding instances of related classes as an association between those classes. This is because properties in C# are by definition operations and not attributes. Associations are represented as attributes in code and not as operations. This behaviour is consistent with the UML specification.

I have elaborated on this issue here and here.

While this is truly a pain, I don't see a way to solve your problem without changing your code (i.e. not use auto-properties and explicitly model associations as attributes), unless Sparx takes this on as a feature request.

Cheers,

Till

Eulinky

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Reverse Engineering: Associations in class dia
« Reply #10 on: August 29, 2014, 05:53:19 am »
@Andy: Drawing this diagram creates classes with fields.
@Till: Yes, I do use auto properties and they are getting translated into operations (with stereotype "property"). I read the discussions and understand the reason up to a certain degree, but in the end it makes EA useless for my scenario: I need to create a model from my 2 million lines source code project.

To do so I need at least my C# properties translated into attributes, so I get meaningful class diagrams without drawing each of my 20 million associations by hand.

Is this really impossible? Isn't there a C# option that says "Import Properties as Attributes"?!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Reverse Engineering: Associations in class dia
« Reply #11 on: August 29, 2014, 06:39:50 pm »
I don't think that option exists.

Yo can do two things.
Either you try to change the reverse engineering template  (which seems complicated and a lot of work)
Or you make a little script/program to add the associations based on the property operations.

The latter should be less then a day's work if you know your way around in the EA API.

Geert

webfox

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Reverse Engineering: Associations in class dia
« Reply #12 on: August 29, 2014, 07:18:44 pm »
If it's only for the reverse engineering part I agree with Geert. However, if the plan is to generate/synchronise code from your reverse-engineered model later on, you'll end up with an attribute being generated for each of the script-generated associations, unless you adjust your code generation templates accordingly. Bear that in mind.

Cheers,

Till
« Last Edit: August 29, 2014, 07:19:25 pm by webfox »

Eulinky

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Reverse Engineering: Associations in class dia
« Reply #13 on: August 29, 2014, 08:17:37 pm »
First, we found a solution that works for our usage:

Tools -> Options -> Source Code Engineering -> Create dependencies for operation return and parameter types

That generates Dependency links at the import. That at least lets us create meaningful diagrams for the start. We just ran in more questions which we have to investigate, I'm sure you will see more questions from us in the upcoming weeks  ;).

Thanks so far to everyone for your support, we wouldn't have come so far without your input!