Book a Demo

Author Topic: Problem with code synchronizing  (Read 2931 times)

murlex

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Problem with code synchronizing
« on: May 05, 2005, 06:57:06 am »
Hello!
Please, advise how can I get reverse/forward code synchronizing working properly in the following situation:
Starting point: I work on the class diagram and then generate code (C# files). Everything is ok. Let say, I have "Class1" and "Class2". I also have an unidirectional association between them: Class1 -> Class2 with multiplicity 1 -> * and role name "Coll" for destination. I set (via Collection Classes option in Code generation for C#) the FinCollection as the Default Collection Class. Let's generate code (from scratch) for Class1. I got the following (and absolutely right!) code:
Code: [Select]

...
public FinCollection Coll;
...

Here my problems about to begin. After reverse synchronizing the model from this code EA automatically adds the +Coll member into attributes compartment of the Class1. So, I have now 1: An association with role name Coll and 2: attribute named Coll (redundant?). But, ok. Let say, I can stand it :) because forward code generating seems know about it and DOES NOT generate TWO lines like this:
Code: [Select]

...
public FinCollection Coll;
public FinCollection Coll;
...

And now - the question: what can I do if I need that the code generated look like that:
Code: [Select]

...
public abstract FinCollection Coll { get; }
...

Obvious answer is the change Code Generation Template. I did that. I changed template for Linked Attribute Declaration and finally got the code I wanted (I even got it conditionally based on stereotype, that gives me possibility turn on/off this code generation behaviour). BUT! When I reverse synchronize such code, EA understand it as the property (and he is right!) and adds the +<<property>> Coll():FinCollection into operation compartment of the Class1.
Now, finally, in order to see my problem let's generate the code for the last time. Alas! We got weird result! Now I have TWO "Coll" members in my Class1.
Code: [Select]

...
public FinCollection Coll;
public abstract FinCollection Coll { get; }
...

Of course "public FinCollection Coll;" is redundant. I understand that 1st was generated due to my association (1 -> *) and the 2nd due to "+<<property>> Coll():FinCollection" that now in compartment of Class1.

The question is: how can I implement proper forward/reverse synchronizing vehaviour in the  case described?
Thanks in advance.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Problem with code synchronizing
« Reply #1 on: May 09, 2005, 03:41:27 pm »
EA creating the attribute when reverse engineering is the intended behaviour, and you shouldn't get any weirdness happening because of it.  (Except for the weirdness of it happening in the first place if you consider it such.)

Quote
what can I do if I need that the code generated look like that:
Code: [Select]
...
public abstract FinCollection Coll { get; }
...

I think that this is where the trouble starts.  In UML, your association represents an attribute.  In EA properties like the above are operations. (There was a conversation concerning this a while back.)

When generating, EA knows that an attribute and an association can be the same thing, but it doesn't know that an attribute and operation can be the same thing.  (Which they aren't)

After all of that, how can you implement the correct forward/reverse synchronising behaviour?  The only way that I can think of is not modelling the association and instead creating an abstract readonly property method.

Simon

murlex

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Problem with code synchronizing
« Reply #2 on: May 09, 2005, 11:58:34 pm »
Actually, I found the way to do almost what I need even without changes in Code Generation templates. I missed the fact I can chose from combobox the role name in case I have the attribute type of Class2 in Class1.
So here the steps I get the behavior I need:
1. Create private attribute of FinCollection type in Class1 with name "_class2"
2. Mark it as Property (this brings Property dialog). Set the name "class2", uncheck Write, check Abstract
3. Draw association and chose the target role name from combobox ("_class2").
As result, I have now generataed all as I wanted, except extra line:
Code: [Select]

private FinCollection _class2;

but it's I can stand. Just the "dead" member, I will never create. I even said to EA do not show it on diagram.