Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » OCL syntax on association ends
OCL syntax on association ends [message #1862623] Fri, 15 December 2023 08:47 Go to next message
Nathan Duchesne is currently offline Nathan DuchesneFriend
Messages: 1
Registered: December 2023
Junior Member

Suppose I have the following data model:
entity Person {
String name
Set(Book) editor oppositeTo editedBy
Set(Chapter) chapterAuthor oppositeTo author
Set(Book) bookAuthor oppositeTo author
entity Book {
String title
Set(Person) editedBy oppositeTo editor
Set(Chapter) chapters oppositeTo book
Set(Person) author oppositeTo bookAuthor
Set(Publisher) publisher oppositeTo publish
entity Chapter {
String title
String text
Set(Person) author oppositeTo chapterAuthor
Set(Book) book oppositeTo chapters }
entity Publisher {
String name
Set(Book) publish oppositeTo publisher
enum Role {

and I want to construct an OCL constraint such as "A user u can associate a Book b with a Publisher p if and only if all the authors and editors of b have already authored at least three chapters in books published by p."

Obviously one way of doing so in
Book is using collect and flatten:
add(publisher) constrainedBy [>union(self.editedBy)->forAll(x |
->collect(y | y.chapters)
->select(c |>includes(x)
)->size() >= 3
and by defining the constraint on the opposite entity as well (in this case, Publisher).

Now comes my question: Is the above query equivalent to:>union(self.editedBy)->forAll(x |
->select(c |>includes(x)
)->size() >= 3

i.e can I link multiple Set associations and will this flatten out the result into one Set, or will this give me a Set of Sets, hence both queries not being equivalent?

Thank you guys for your time and don't hesitate if you need any more specifications!

Re: OCL syntax on association ends [message #1862637 is a reply to message #1862623] Sat, 16 December 2023 16:27 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7665
Registered: July 2009
Senior Member
(Your use of target rather than x is presumably a typo.)

OCL evolved for use with UML whose multiplicities become collections. There are no nested multiplicities consequently OCL was defined to always flatten nested collections. This design mistake was mitigated/confused by the addition of collectNested and flatten.

In your example the eager flattening should indeed make the expressions equivalent.
Previous Topic:Examples of def: taking OclLambda parameter?
Next Topic:Unable to install OCL 6.19 Tests in 2023-12
Goto Forum:

Current Time: Sat Jul 20 14:16:16 GMT 2024

Powered by FUDForum. Page generated in 0.03759 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top