The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

OOP and UML question

Hello, please take a look at the following code

class Person {
  int number;
  Salary salary;
}

class Salary {

}

I'm a little confused about what to use in UML for this situations regarding Person - Salary.

Is it "Association" or "Agrregation"? I think it's agregation.

Thanks.
Dont remember by OMT classes
Monday, November 05, 2007
 
 
Depends on the semantics of your domain.

If each person has a salary that's unrelated to any other person's, then I'd say: aggregation - person has-a salary.

If salaries exist independently, e.g., a set of predefined salary grades, then I'd say: association - person earns salary (grade).
Mike Stockdale Send private email
Monday, November 05, 2007
 
 
it is an association

Association represents the ability of one instance to send a message to another instance. This is typically implemented with a pointer or reference instance variable, although it might also be implemented as a method argument, or the creation of a local variable.

[Example:]

|A|----------->|B|

class A
{
  private:
    B* itsB;
};

ref:Robert C Martin
Ashish Jaiman Send private email
Monday, November 05, 2007
 
 
Totally depends on your domain model.

Do your Salary objects have identity within the domain? 

Unless salary is working to a grading scheme, it is unlikely Salary objects have unique identity, therefore Salary objects could be considered 'value' objects. 

Value objects are always aggregated within entity (uniquely idenitified) objects, so you probably want to be using the Aggregate symbols for your UML diagrams.
sensible
Monday, November 05, 2007
 
 
I"m genuinely interested, not giving you a hard time ... what difference does it make? Will the code be different? Will readers misunderstand your intent?
Stan James
Monday, November 05, 2007
 
 
"what difference does it make? Will the code be different? Will readers misunderstand your intent?"

If one is usng UML to document a domain then one ought to use it properly else risk a misunderstanding or two.
sensible
Tuesday, November 06, 2007
 
 
Or stop at a level of abstraction that omits details that don't matter. :-)
Stan James Send private email
Tuesday, November 06, 2007
 
 
"I"m genuinely interested, not giving you a hard time ... what difference does it make? Will the code be different? Will readers misunderstand your intent?"

Just making some UML documentation of the classes, trying to be precise.

Thanks for your explanations. Salary wasn't a very good example, but the actual object is mapping a database association with it's own "identity", so its association from the descriptions above.
Dont remember by OMT classes
Wednesday, November 07, 2007
 
 
Unfortunately there is no proper/right/correct/"one" way. I'm just finishing a UML prject and went through this same discussion. For me, I don't see any value in aggregation as opposed to association. Composition has semantics, so there is value, but aggregation does not enforce any semantics. Read up more here to see where I got this opinion:

http://martinfowler.com/bliki/AggregationAndComposition.html
Scott K.
Wednesday, November 07, 2007
 
 
It's containment. Use the filled diamond association shape and point to Salery.
Marc Jacobi Send private email
Friday, November 09, 2007
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz