Setting Multiplicities for a Reference Variable
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.
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)