0

I am new to OCL, and I just came across this expression:

context Person::descendants(): Set  
 body: result = self.children -> union(
 self.children -> collect(c | c.descendants()))

I now that it's trying to obtain the direct and indirect descendants of a person, but how is that written here, what each sentence is trying to say?

Also this one,

context Person::income(): Integer  
body: self.job.salary -> sum()

Is this recursive?

Arwa
  • 575
  • 1
  • 5
  • 17

1 Answers1

0

result = is gratuitous fluff to convert an OCL query into the narrow UML requirements for a Boolean valued body condition. IMHO it should be deleted, and some tools may do so for you.

self.children is the direct children

x->union(y) combines two sets

c.descendants() is a recursion invocation of the descendants()

self.children -> collect(c | c.descendants()) is the recursion applied to each child and with the result accumulated as a Bag


There is now a closure() iteration so I would write

context Person::descendants(): Set(Person) body: children->closure(children)

Regards

Ed Willink

Ed Willink
  • 1,205
  • 7
  • 8