Reputation: 1544
I have 2 classes Job
and Task
. These are the rules:
Job
has a numeric identifier.Job
has 10 corresponding Task
s.Task
has a numeric identifier.Task
cannot exist without a Job
.I am trying to build Class diagram for these 2 classes. Since Task
cannot live without Job
so I thought this is a composition and this is how I build the Class diagram:
But now I am confused that if this association is actually dependency:
How can I know in this case if the relationship is composition or dependency?
I have fixed the composition (Composite Aggregation) in the Class diagram as Thomas Kilian suggested:
Upvotes: 3
Views: 394
Reputation: 36295
A dependency is the weakest relation between elements. It means that if the element which is depended on is changed it needs some kind of attention in the depending element. E.g. there can be dependencies on enumerations or in a conceptual phase between classes or between packages if they contain associated classes.
A composite aggregation is in first place a strong relation (an association) between two elements. That is one of both is also working with the other side in some way (using attributes or methods). Further the composite aggregation is telling something about object lifetimes. The elements being composed will die once the compositing element is removed. This is merely a construct used for data security e.g. where you need to delete personal records if the person is removed (the car/wheels example does not seem to make so much sense since the wheels still are useable once the car is crashed). Another use could be (nowadays less) storage management.
Two side notes:
Your drawing is wrong as the filled diamond must attach to the outside and not to the inside of the shape.
The shared aggregation (hollow diamond) has no defined semantics and should only be used once you define it in a certain domain for a specific use. See p. 112 of the 2.5.1 specs:
Indicates that the Property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler.
Upvotes: 4