Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a uml question

 
suekar meredilko
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Folks,

I am trying to understand how to interpret a class diagram from coding perspective, i.e. the Implementation perspective for relationships like Association, aggregation, composition, dependency, generalization etc.

Is there a definitive guide available ? I saw there is in general no rule of the thumb.

Any thoughts on this would be helpful.

for e.g. a customer and product class may have a dependency relationship
then customer may either have a either reference variable or in more loose terms a function may be using the variable localy.

similarly, does a composition/aggregation have to be a member variable.Sometimes even associations are modelled as member variables. Is there any specific guideline on this or it depends on the scenario and exactly what you want to capture in your project.

pls. let me know.

thx in advance
 
Sreenivasa Majji
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UML is conceputal at best and programming languages are implementation at best. When you see an association or dependency in UML, that doesn't mean that you have to have similar structure in the implementation language. Some times both are same or both of them not available. We can implement the same UML concept in different ways in the implementation langugage. Your UML should be independent of implementation language.

The closest book I can think of is 'UML for Java programmers', but this also doesn't tell you how to differentiate between aggregation and composition (in Java syntax).

my $.02
 
Ramen Chatterjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For aggregation/composition, the difference is in the lifetime of the objects. A parent object that aggregates children objects, will allow the children objects to live on beyond it. However with composition, when the parent dies, the children die.

I like to think of it like this:

Aggregation - a shopping cart has items in it, the items could exist without the cart. The item can exist menaingfully outside of the cart (in my cupboard perhaps)

Composition - A person has a brain, when the person dies the brain dies too. A brain has no business living on beyond the person!

Regards

Ramen
 
Samuel Pessorrusso
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Composition - A person has a brain, when the person dies the brain dies too. A brain has no business living on beyond the person!


Ok, but let's think in other example:

Car has different configurations (let's imagine that you can setup you car to use 6 seats or just 2 ). Is this a composition (Car and Configuration) or is this just an directed association between Configuration and Car ?

Example:
Car <-------- Configuration


I'm using a directed association because I don't think it is right to make Car directed to Configuration.

Any comments?
[ May 16, 2006: Message edited by: Samuel Pessorrusso ]
 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is aggregation relationship.
 
suekar meredilko
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as per martin fowler, aggregation does not provide any thing special and one can ignore it. by far 'implementation wise', association and aggregation would be about similar.

that brings me to the actual question.
honestly a bit dissapointed most you are answering a question which I know. What I am really interested in knowing is how do you interpret class diagrams and do the actual implementation. As you knwo there are 3 different types of class diagrams conceptual, specification and implementation. the implementation perspective gets you v. near to the actual code implementation.

so what i wanted to know in the first place is that how does aggregation, composition and dependency is shown in terms of coding. would it be using private member variables for association (directed) and dependency and composition (make sure that when the whole dies, part dies as well)

hope I am clear in my question. - thanks
 
Ramen Chatterjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suekar

Apologies if I was missing your point. My feeling is, (and I am still learning this stuff) that all of them will translate to a member variable, and good encapsulation would make them private member variables. As for lifetime management, Im a bit more fuzzy. Dependencies show which of the classes holds a reference to the other (could be bi-directional) - hope this is more helpful.

Samuel

Point taken, bad example in so far as a person only has one brain - perhaps it would have been better if i had said a person has many organs?

Regards

Ramen
 
S Agarwal
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Samuel
------------------
I'm using a directed association because I don't think it is right to make Car directed to Configuration.
------------------

I could be wrong but in your example, you made a direction from Configuration to Car... Just thinking whether Car can access its Configuration OR Configuration can access Car? The earlier one seems right to me.

Any thoughts.
 
Samuel Pessorrusso
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by S Agarwal:
I could be wrong but in your example, you made a direction from Configuration to Car... Just thinking whether Car can access its Configuration OR Configuration can access Car? The earlier one seems right to me.


But if you think that in you code a Car won't need to access it's Configurations and the Configurations must access the related Car (to get the Car model, etc), my solution will look feasible, won't it?

Let's think in other way, instead of Cars, think about ... Trains!! Let's imagine that each train travel has it's own configuration, therefore a Train can have a lot of Configurations. If you make a Train object able to access it's configuration you are going to put a lot of objects in the memory.

Any comments ??

[ May 18, 2006: Message edited by: Samuel Pessorrusso ]

[ May 18, 2006: Message edited by: Samuel Pessorrusso ]
[ May 18, 2006: Message edited by: Samuel Pessorrusso ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic