Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting Multiplicities for a Reference Variable #4

Open
ialazzon opened this issue Jun 21, 2022 · 1 comment
Open

Setting Multiplicities for a Reference Variable #4

ialazzon opened this issue Jun 21, 2022 · 1 comment

Comments

@ialazzon
Copy link

How can one set the multiplicity for a reference? For example, let authors be a reference variable in class Book to Person. A book can have zero or more authors. How to set the multiplicity lower and upper bounds for the variable authors in class Book?

Thank you for your help.

@aranega
Copy link
Member

aranega commented Jun 21, 2022

Hi @ialazzon,

Thanks for the ticket, once again, as you probably saw, the way of setting a cardinality for a Property is really really not straight forward.
You need to deal with the upperValue and lowerValue property of the Property object, but you don't need to directly put an integer, but a ValueSpecification instance instead.
Typically, you can use LiteralInteger for simple integer values and LiteralUnlimitedNatural for multiple value (for the upper bound).
Here is how to define a property with a cardinality 0..* and 1..5:

import pyuml2.uml as uml2

# cardinality 0..*
p = uml2.Property()
p.lowerValue = uml2.LiteralInteger(value=0)
p.upperValue = uml2.LiteralUnlimitedNatural(value=-1)  # will be encoded and serialized as "*"

# cardinality 1..5
p = uml2.Property()
p.lowerValue = uml2.LiteralInteger(value=1)
p.upperValue = uml2.LiteralInteger(value=5) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants