0

I have a class diagram with the following two aggregations:

Aggregations constraint problem

contentCategories is a dynamic array of categories, currentCategory is always an element of that array, but is maintained as a distinct member variable. I need to show the constraint that it is always an element of contentCategories in OCL. Have I done this correctly? If not, what would be the correct way to do it?

Thank you all for your help in advance!

tommazzo
  • 323
  • 1
  • 4
  • 13
  • Perhaps you can keep an index like, CurrentCategoryIndex, instead of keeping an object that already exists in the array. – Nazar Merza Mar 29 '12 at 16:56
  • Having the pointer to the object directly allows me to save the time needed for indexing into the array all the time, although this would be negligible given the number of accesses to the object in my case. Anyway, there is no way I can update this any more. Thanks anyway. – tommazzo Mar 31 '12 at 21:04

1 Answers1

1

Yes, your idea is right. I would write the constraint in a comment, though, and w/o a dashed line

EDIT: sorry, in order to be "academically sound" your OCL constraint should also be correct even if there is no currentCategory. That means, the constraint'd better read

not currentCategory==null implies contentCategories -> includes(currentCategory)
gefei
  • 18,922
  • 9
  • 50
  • 67