Book a Demo

Author Topic: associate connectors when reverse engineering  (Read 14205 times)

darrenw

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
associate connectors when reverse engineering
« on: August 07, 2005, 11:18:12 pm »
I've reversed engineered a c# component and discovered it has used association where I would have used composition. For example if I have a class called Customer and it contained a class called Address as per the following code:

class Customer
{
   private Address address=new Address();
}

It has created an Association connector between the two pointing to the Address class.

Is it possible to tell it to use the Compose connector and have the coloured in diamond on the Customer side when reverse engineering?

I assume I'm correct here saying that when Customer is destroyed, so too is Address so using the compose connector would be correct.

Thanks,
Darren.

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: associate connectors when reverse engineering
« Reply #1 on: August 07, 2005, 11:53:16 pm »
Sorry Darren but no.

This has been posed many times in this forum.  You might get solace through searching for other replies than mine.

"Composition is one of the stupidest things OMG put into UML"

You may quote me.

Composition is a behavioural aspect of an association.  It has no right to be in a structural model.

Composition conveys no other value semantic other than behaviour in that when you immolate the owning object, you immolate any and all of the owned objects (if indeed there can be more than one of the owned objects).  On its own admission OMG admits that creation of the owner does not neccessarily imply creation of the owned.

Given all that, reverse engineering of a class association into a composition would require the engine to locate a destructor in the methods, analyse the associations and decide that "here" would be a good place to put a diamond.

scuse the harshness of the reply.


bruce


"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: associate connectors when reverse engineering
« Reply #2 on: August 08, 2005, 02:54:11 am »
Just to reinforce bruce's response.  Composition and aggregation are both forms of meronymy (the whole-part) relationship.  Unfortunately because UML only supports two of the commonly accepted 6 forms of meronymy, it creates an overlap which causes a lot of confusion.  Both bruce and I have had a lot to say about it.  Search for Aggregation, Containment, Composition or Meronymy to get a flavour.

The problem is also compounded by some bugs in the the management of the association and in the fact that EA actually has an Aggregation connector (as distinct from the Association connector) - which as bruce implied is the actual UML representation.

And bruce is right, but didn't express himself quite correctly:   The "filling" of the diamond (not composition vs aggregation) describes the control that the "whole" has over the immolation of the "part"...  A filled diamond says the whole can destroy the part, unfilled says it can't.

HTH,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

darrenw

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: associate connectors when reverse engineering
« Reply #3 on: August 08, 2005, 04:54:33 pm »
Thanks for the replies. My next question is, if I change the connector types and update them to the appropriate type, will I lose this when I reverse engineer the source code again (using synchronize existing classes)? We are using EA as a modelling tool and update the model after each build rather than getting it to generate the source code, is this what most people do or is there a better way?

Thanks,
Darren.

thomaskilian

  • Guest
Re: associate connectors when reverse engineering
« Reply #4 on: August 09, 2005, 01:31:17 pm »
Quote
... if I change the connector types and update them to the appropriate type, will I lose this when I reverse engineer the source code again (using synchronize existing classes)? ...

It's just a few clicks to let EA give you the answer.

darrenw

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: associate connectors when reverse engineering
« Reply #5 on: August 09, 2005, 10:04:03 pm »
Well no it doesn't, I'm not running tests against the production model and interrupting other developers. Thanks for the help.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: associate connectors when reverse engineering
« Reply #6 on: August 09, 2005, 10:38:00 pm »
Quote
Thanks for the replies. My next question is, if I change the connector types and update them to the appropriate type, will I lose this when I reverse engineer the source code again (using synchronize existing classes)? We are using EA as a modelling tool and update the model after each build rather than getting it to generate the source code, is this what most people do or is there a better way?

Thanks,
Darren.
Well, Darren, the answer is probably already before you.  You have observed that you have a loss of information when round trip engineering.  If you search the forum you'll find the results I had with generalization versus realization and round-trip-engineering.

Since programming language grammars are more constrained than modelling grammars, you can always define a one-to-one (or many-to-one) transformation from the model to the code.  But since you can't always go the other way (without additional information), the idea of round trip engineering (using pure code only) is a fallacy, in my view.

If all you want to do is to create some contractual obligation documentation of some models, then RE is a possible solution.  "Create a pretty picture and the punters won't know the difference."  But I have to tell you the increasingly, the punters DO know the difference!

If however, you are enthused with the idea of writing code via a model, then RE basically sucks unless you can get the RE engine to be able to understand the subtleties of comparing the actual code with the model's intent.   Since you can't control the RE engine (its in Sparx's hands) and you have only limited control of the code generation engine (via the CTF) this is somewhat problematic.

Consequently, for my own part, I've taken the route of only forward generating the code (with some capability for refactoring existing code).  Further, I've decided that I'm going to take the UNIX type route and use the tools for their best advantage.

EA is the modelling tool of choice.  CodeSmith is the code generation tool of choice.  I'm defining an interface that allows me to describe conceptually what I want done and a mechanism to allow me to turn that into code (or narrative or DB design or testing) at some level of abstraction.

I'm currently working on an automaton to emit the conceptual model, and a separate automaton to generate code.  Once I get enough of it working I'll create a model of the automaton and get the model to emit the code that generates itself.  After that, it's bootstrap time...

HTH,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: associate connectors when reverse engineering
« Reply #7 on: August 10, 2005, 12:05:49 am »
From earlier
Quote
The "filling" of the diamond (not composition vs aggregation) describes the control that the "whole" has over the immolation of the "part"...  A filled diamond says the whole can destroy the part, unfilled says it can't.


Dont know whether I agree with the fine print there pardner!

(IMO) All UML composition says is that the part cannot exist without the owning element**.  Who or what does the immolating is not specifically mentioned.  Again, they've left that small detail up to the implementers.

The possible corollaries are, as you say undefined in terms of meronymistocity (whatever).  Can the whole exist without the part - according to OMG yes.  Destruction of the whole implies destruction of the parts, but the responsibility thereto is not specified.    

I'll go even further.  The "whole" is in fact the (super)sum of the parent (the owning element) and the parts.  There is a boatload of implications and bad assumptions created because the name of the whole is usually applied to the owning element and not to the real whole.

So to go back to ** above, existence of the part does not necessarily depend on existence of the owning element, but as you say, on existence of the whole.

Going even further!  The presumption that an owned object ceases to exist on the demise of the owner is a bit restrictive.  The truth is, the characteristics of the part that are evinced through its participation in the whole may cease to exist but oftentimes the part remains - albeit usually in a new role.

Class Frog::iAmphibian {
frogbit[2] Legs;
frogbit[..] Otherbits;
public Legs Frog.ChopUp();
}

There are zillions of lines of code being written today just  to cope with this type of excision.  Dont believe me?

Order<*>--OrderLineItem
Invoice<*>--InvoiceLineItem
Receipt<*>--AllocationLineItem
Stock<*>--InventoryItem
.....

These xxItems are all just the same froglegs, but how many lines of creates, moves and copies are being written to cope.



Anyway its all behavioural and shouldn't be in a structure model.
bruce


« Last Edit: August 10, 2005, 12:07:52 am by sargasso »
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

mikewhit

  • EA User
  • **
  • Posts: 608
  • Karma: +0/-0
  • Accessing ....
    • View Profile
Re: associate connectors when reverse engineering
« Reply #8 on: August 10, 2005, 12:34:08 am »
Quote
Anyway it's all behavioural and shouldn't be in a structure model.
But object lifecycle is a uniquely special type of object behaviour ...

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: associate connectors when reverse engineering
« Reply #9 on: August 10, 2005, 04:04:21 am »
Quote
From earlier

Don't know whether I agree with the fine print there pardner!
Well, bruce, I wasn't as clear as I should have been in my choice of words.  In the "fine print" - which quoting doesn't copy - I meant can as in is able to not as in must
Quote
(IMO) All UML composition says is that the part cannot exist without the owning element**.  Who or what does the immolating is not specifically mentioned.  Again, they've left that small detail up to the implementers.
Actually, I got the opposite impression: in composition there is a structural and/or functional relationship between the whole and the part such that if you take away sufficient parts, you no longer have the whole.  Or that the part does not exist without the context of the whole.  
I agree with you that the immolation thing has got in the way of correctly understanding what's going on.  However, given my definition above, if you have one of my compositions, it must be the case that if the whole is destroyed, the parts (at the time) must also be destroyed.  I'm not saying the whole destroys them necessarily, but they are gone none the less.  (However, see later)
Quote
The possible corollaries are, as you say undefined in terms of meronymistocity (whatever).  Can the whole exist without the part - according to OMG yes.  Destruction of the whole implies destruction of the parts, but the responsibility thereto is not specified.
Meronymy, meronymy, meronymy ;D
Yes, the whole can exist without the part!  That's one of the tests for simple aggregation.  I can have a team with no players.  I can have an empty collection.  I certainly don't have a composition.  I don't even have a container!
Quote
I'll go even further.  The "whole" is in fact the (super)sum of the parent (the owning element) and the parts.  There is a boatload of implications and bad assumptions created because the name of the whole is usually applied to the owning element and not to the real whole.
Ah.. Here it depends on the relationship between the whole and the part...  If the whole is an collection or a container, then the name does only apply to the whole and not to the part.  On the other hand if you have a composition like I defined above then your assertion is indeed correct!  To be a bicycle, I need to have two and only two wheels.  Each wheel is not the bicycle and the bicycle is more than the two wheels.  Take one wheel away, and I have either a broken bicycle or a unicycle!  Add a third wheel and I have a tricycle.
Quote
So to go back to ** above, existence of the part does not necessarily depend on existence of the owning element, but as you say, on existence of the whole.
See how I've turned it right around?  The crucial test, for me, is can the whole exist without the parts?  ..And which parts.  I think we can say that when we have composition, we can declare some canonical set of parts that constitute the whole and other parts that merely adorn or enhance the whole.  Thus in the bicycle example, it may have handle bars, but they aren't essential to it being a bicycle.
Quote
Going even further!  The presumption that an owned object ceases to exist on the demise of the owner is a bit restrictive.  The truth is, the characteristics of the part that are evinced through its participation in the whole may cease to exist but oftentimes the part remains - albeit usually in a new role.
Now you come to the crux of the question - and again it's about the relationship.  Take a room in a house, without rooms, you can't have a house.  However, if you take the house away, you don't have rooms.  But some rooms (like demountables) can be added to a house and taken away from the house.  What's going on here?  In my view, it's about what happens at the time of destruction.  If the wheel is on the bicycle when I destroy the bicycle, then the wheel is also destroyed.  If it's not it isn't.  That's why it warrants the filled diamond.
Quote

Class Frog::iAmphibian {
 frogbit[2] Legs;
 frogbit[..] Otherbits;
public Legs Frog.ChopUp();
}

There are zillions of lines of code being written today just  to cope with this type of excision.  Don't believe me?

Order<*>--OrderLineItem
Invoice<*>--InvoiceLineItem
Receipt<*>--AllocationLineItem
Stock<*>--InventoryItem
.....

These xxItems are all just the same froglegs, but how many lines of creates, moves and copies are being written to cope.
These depend on how they are defined and modelled.  If you define the Order as the (super)sum of the common Order  Header data and the set of Order Line Items, but require that an order must have at least one line item, then the order can't be persisted without a line item.  Here you have a composition.  If you consider it like a collection and allow empty orders (for whatever reason) then you have modelled it as an aggregation.  Certainly, an Order Item can't exist on its own since it automatically creates a new order (That is, an order item is always part of an order even if it is the only item on that order.)  Since this is part of the business model, each enterprise has a degree of control as to how it wishes to represent all of these order cycle concepts.  However, just for a minute going back to my world vs business vs system model, my advice would (and has been), if you also require that the order be a contract to supply, then contract law (in most jurisdictions) requires that there be a good to supply for some consideration and thus composition is better than aggregation.
Thus when I have removed the last Order Item, I have destroyed the Order.  If I destroy the Order, I must destroy all the Order Items currently comprised - since they have no life on their own!  If I wish to save an Item, I must excise it from the order to be destroyed first.
Note, although we colloquially say the team died in the air crash, what actually happened is ALL the current members of the team died in the air crash.  The team is dead, long live the team...
Quote
Anyway its all behavioural and shouldn't be in a structure model.
bruce
Well, I hope I've shown it is more than just behavioural...  (Although I agree with you that there are a whole lot of behavioural consequences to the use of the right form of meronymy).  I'm not agreeing with mikewhit that object life cycle is a special form of behaviour.  I'm saying that the notion of composition is inherent in the definition of the whole (regardless of life cycle).

Meronymously... ;D
Paolo
« Last Edit: August 17, 2005, 10:02:49 pm by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Ilja Kraval

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
  • I love YaBB 1 Gold!
    • View Profile
Re: associate connectors when reverse engineering
« Reply #10 on: August 10, 2005, 08:23:25 am »
Relationship "composition" isn't only question of behaviour, but it is about context of information (staritng in analysis). For analytics it means, what must be in system "fetched" like instance of information, and it has relevant interpretation.

As an example one stupid, but pertinent joke, when somebody overlooks character composition and "fetched" information hasn't relevant context:

... television sports commentator: "And now several nice results from tennis... 7:5, 6:4 and 10:8!"

:)
Ilja


« Last Edit: August 10, 2005, 09:56:56 am by Ilja »
RNDr. Ilja Kraval,
Object Consulting,
Czech Republic

Gary W.

  • EA User
  • **
  • Posts: 139
  • Karma: +0/-0
    • View Profile
Re: associate connectors when reverse engineering
« Reply #11 on: August 10, 2005, 12:51:23 pm »
Quote
Well no it doesn't, I'm not running tests against the production model and interrupting other developers. Thanks for the help.


On a totally unrelated note, I should point out that most (all?) IT shops I've worked at have several environments, such as:
- personal dev
- shared dev
- test
- migration
- production, etc.

At the very least, you should have a 'sandbox' application where you can import (parts of) your production model, test out the proposed changes, and then incorporate the final results into the migration process.

This way, you have no worries about screwing up the production model... well, at least not by doing these sorts of tests.

We still get the odd "oops, I didn't mean to delete the entire model" comment, which is when the backup strategy comes into play.. but that's a whole other story =8^)

Gary

thomaskilian

  • Guest
Re: associate connectors when reverse engineering
« Reply #12 on: August 10, 2005, 03:22:04 pm »
Quote
...
Consequently, for my own part, I've taken the route of only forward generating the code (with some capability for refactoring existing code).  Further, I've decided that I'm going to take the UNIX type route and use the tools for their best advantage.
...

I almost allways did it this way. Maybe it's mainly because I had no RE for the languages I used, but I simply decided that THE MODEL is leading - not the product (code).

thomaskilian

  • Guest
Re: associate connectors when reverse engineering
« Reply #13 on: August 10, 2005, 03:25:09 pm »
Quote
...
Gary

I was upon writing the same, but I also know that REAL programmers are tough and don't need any sandbox  ;)

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: associate connectors when reverse engineering
« Reply #14 on: August 10, 2005, 03:27:14 pm »
Re Gary's post:

Indeed!

My "standard" EA base model includes a WIP view which I encourage all modelling work to be initiated in, tested in, b*ggered around with etc before the result is moved into the formal model views.

EA makes it easy to do this type of model prototyping (and "EA testing").

bruce
« Last Edit: August 10, 2005, 03:31:26 pm by sargasso »
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.