Question

I am writing a job tracking application where the job seeker can apply for jobs and keep track of the records. when i try to design the model using uml , I got a question.

Job (class)
---
id:int
position:String
status:String

Comments (Class)
--------
id:int
comment:String
job:Job

I was asking myself few questions to understand whether this is a composition or aggregation?

  1. Should the comments deleted when the job is deleted? Yes , then is this composition?
  2. Job owns comments? people always ask this question, but we cannot exactly ask this question in this case? Because car owns a wheel? yes , can we ask Job owns comment?

I dont know whether this is an appropriate question. I was worrying so much that I will get minus points in stackoverflow if the question is not appropriate. But I really wanted an answer, hence posting this. Any help would be appreciated.

Thanks, Arun

Was it helpful?

Solution 2

Aggregation is a subset of association. Composition is a subset of aggregation. So, putting OR between them is not so correct.

Should the comments deleted when the job is deleted? Yes , then is this composition?

If they are deleted, it IS a composition. But it is YOU who have to decide how you'll organize your classes. You can make comments not so dependent and it will be a shared aggregation or association with none aggregation

OTHER TIPS

In my opinion Job should refer Commons and not the other way around. Your design is more an ER then an UML diagram. And I think the Comment shares its life-cycle with Job, because if the Job is gone, the Comment has no context anymore. Hence, it is a composition.

The UML in my opinion is:

Job (class)
---
id:int
position:String
status:String
comment:Comment

Comments (Class)
--------
id:int
comment:String
  1. I think logically, Job should have Comments. And the relationship should be composition. Comments will be based on job, if Job doesn't exist, then there is no point of having comments.

There are various semantics I've seen over the years for aggregation and composition, but UML's have become something of a de facto standard.

UML states that an aggregation relationship indicates a whole part relationship which is "transitive and anti-symmetric". The "transitive" part means that if C is part-of B and B is part-of A, then C is part-of A, which makes intuitive sense. The "anti-symmetric" part means that you cannot have cycles in the aggregation graph, meaning that an object may not be directly or indirectly part of itself, which also makes sense intuitively.

Composition (or "composite aggregation" as UML terms it) is aggregation with the additional constraints of "strong ownership" (a part may only be part of one composite at a time) and "coincident lifetimes" (so parts contained within a composite at the time of its deletion are deleted with it).

For Job and Comment, in my judgement it is definitely composition because a comment wouldn't be shared between jobs and when you remove a job you would remove its comments at the same time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top