i had this question on my test this week and i’d like to know your opinions on it.
Translate this sentence from English to Object Constraint Language (OCL)
An employee can only be a trainee manager of a branch at which they are already an employee.
And this is my try
Context Branch inv
Self.trainee.manager = self.employee
What do you think?
the base class should be Branch
To me, I’d be looking for set operations since I assume that branches have more than one employee.
Assuming that Branch.employee is actually describing a set of employees and Branch.trainee is a set of trainees. Then the OCL expression I would use is:
Context Branch inv
self.employee->includes(self.trainee.manager)
The includes operation returns true if the given object is included in the set. For example, the above is asking whether self.trainee.manager is included in the set, self.employee. In other words, any branch trainee manager is a branch employee.
Honestly, it’s been a while since I’ve done OCL but hopefully that helped.