A Trainee at most belongs 1 trainee project at a time

That can be shown through a constraint saying for a given trainee the dates of the projects never overlaps.

In OCL the constraint can be written :

context Trainee inv:
 self.ProjectHistory->forAll(h1,h2 |
                             h1<>h2 implies (h1.dateCompleted < h2.dateStarted) or
                                            (h1.dateStarted > h2.dateCompleted))

also having :

context ProjectHistory inv:
   self.dateStarted <= self.dateCompleted

supposing dateCompleted is set with the current date while the project is on going, and we know the project is on going through an other way.

If dateCompleted values 0 while a project is on going :

context ProjectHistory inv:
  (self.dateStarted > 0) and 
  ((self.dateCompleted = 0) or (self.dateStarted <= self.dateCompleted))

context Trainee inv:
  self.ProjectHistory->select(dateCompleted = 0)->size() <= 1

context Trainee inv:
    ->forAll(h1,h2 | 
             h1<>h2 implies 
               if h1.dateCompleted = 0 then
                 h1.dateStarted > h2.dateCompleted
                 if h2.dateCompleted = 0 then
                   h2.dateStarted > h1.dateCompleted
                   (h1.dateCompleted < h2.dateStarted) or 
                   (h1.dateStarted > h2.dateCompleted)

Out of that to use an association-class is a right way.

Over time, Trainees may take more than one project.

so any number, the multiplicity 0..1 must be 0..* or the shortcut *.

The multiply must be 0..1 if that rule and the previous are replaced by (over time) a Trainee at most belongs 1 trainee project

A section may run more than one project.

so any number, the multiplicity 1..* must be 0..* or the shortcut *

A Project can have may trainees

may is visibly many so the high number is not 1.

Just having a project have many trainees probably implies the minimum number is ,1 but with can have the minimum number is 0 rather than 1.

So finally the multiplicity is 0..* or the shortcut *, rather than 1..1

How would previous projects get retained?

they are thanks to the multiplicity 0..* rather than 0..1, the trainee does not have a relation to only the ongoing project if exist

To summarize :

enter image description here

Example of object diagram :

enter image description here

you can check all the rules are followed.

In several case the name of your attributes contains the name of the class, for instance projectName and traineeId, this is useless and I recommend you to remove the name of the class in the name of the attributes.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top