codeable_models.CAssociation¶
-
class
codeable_models.CAssociation(source, target, descriptor=None, **kwargs)¶ CAssociationis used for representing associations. Usually associations are created using theassociationmethod ofCClassifierwhich calls the constructor ofCAssociationto actually create the association (i.e.,CAssociationcould also be used directly).Superclasses:
CClassifier- Parameters
source (
CClassifier) – The source classifier of the association.target (
CClassifier) – The target classifier of the association.descriptor – An optional descriptor making it easier to define associations with a simple string. The descriptor syntax is described below.
**kwargs –
Pass in any kwargs acceptable to superclasses. In addition,
CAssociationaccepts:multiplicity,role_name,source_multiplicity,source_role_name,aggregation,composition,stereotypes.multiplicity:Used to provide the target multiplicity of the association. Defaults to
*. See documentation of the propertymultiplicityfor the accepted syntax.
role_name:Takes a string specifying the target role name and stores it in the same-named attribute. Defaults to
None.
source_multiplicity:Used to provide the source multiplicity of the association. Defaults to
1. See documentation of the propertymultiplicityfor the accepted syntax.
source_role_name:Takes a string specifying the source role name and stores it in the same-named attribute. Defaults to
None.
aggregation:Takes a boolean argument. If set to
True, this association is set to be an aggregation, else it is not. Also, if set toTrue, it sets the propertycompositiontoFalse.
composition:Takes a boolean argument. If set to
True, this association is set to be a composition, else it is not. Also, if set toTrue, it sets the propertyaggregationtoFalse.
stereotypes:Takes a single or a list of
CStereotypeobjects which extend this association. Extension is only possible, if this association is an association between meta-classes.
-
role_name¶ A string specifying the target role name.
-
source_role_name¶ A string specifying the source role name.
Please note that the
nameproperty derived fromCNamedElementis interpreted as the label of the association.Descriptor Syntax:
The
descriptorhas the following syntax:?<label>:? \ ?[<source_role_name>]? <source_multiplicity> ->|<>-|<*>- \ ?[<target_role_name>]? <target_multiplicity>With it, first the label of the association can be optionally specified. Source and target multiplicity strings, in the same form as accepted by the
multiplicityproperty, must be specified, too. They are divided by an arrow determining the type of association:->for ordinary associations,<>-for aggregations, and<*>-for compositions. Optionally in square brackets the source and target role names can be specified right before the multiplicities.Please note that first the keyword arguments are evaluated and then the descriptor. So the descriptor would override settings made in the keyword arguments.
Examples:
The following specifies a
0..1to*association from a classcartto a classitemlabelledin cartwith source role namecartand target role nameitem in cart:cart.association(item, "in cart: [cart] 0..1 -> [item in cart] *")
The same can be specified more verbosely with kwargs:
cart.association(item, name="in cart", role_name="item in cart", multiplicity="*", source_role_name="cart", source_multiplicity="0..1")
Main Relations:
The main relations of
CAssociationare shown in the figure below.
A
CAssociationis need in order to deriveCLinkobjects, which link objects in an object model. TheCAssociationis the classifier of theCLink.As can be seen, a
CAssociationcan be extended by stereotypes. ACLinkcan have stereotype instances of anyCStereotypedefined on the link’s association.The
CClassifiercan be introspected for itsassociations. The association stores itssourceandtargetclassifiers.-
property
aggregation¶ Takes a boolean argument. If set to
True, this association is set to be an aggregation, else it is not. Also, if set toTrue, it sets the propertycompositiontoFalse.- Type
bool
-
property
attributes¶ Overridden method from
CClassifier. Attributes on associations are not supported.
-
property
composition¶ Takes a boolean argument. If set to
True, this association is set to be a composition, else it is not. Also, if set toTrue, it sets the propertyaggregationtoFalse.- Type
bool
-
delete()¶ Deletes this association. Removes the association from all classifiers and links. Removes it from all stereotypes, too. Calls
delete()on superclass.- Returns
None.
-
get_opposite_classifier(classifier)¶ Given a classifier, this method returns the opposite in the association, i.e. the source if
classifieris the target, and vice versa. Raises an exception ifclassifieris neither source nor target.- Parameters
classifier – The classifier from which we want to get the opposite in the association.
- Returns
The opposite classifier.
- Return type
-
property
multiplicity¶ Getter and setter for the target multiplicity of the association. The multiplicity string has the following syntax:
<lower_multiplicity>..<higher_multiplicity>|<single_multiplicity>.The multiplicity is either specified as a range or using a
<single_multiplicity>. Accepted<single_multiplicity>values are any positive number, zero, or*.*denotes unbounded multiplicity.For multiplicity ranges,
<lower_multiplicity>is zero or any positive number specifying the lower end of the accepted multiplicity range.<higher_multiplicity>is a number specifying the higher end of the accepted multiplicity range. It must be higher than<lower_multiplicity>. It can also be*meaning unbounded higher multiplicity.*multiplicity is equal to the range0..*.- Type
str
-
property
source_multiplicity¶ Getter and setter for the source multiplicity of the association. Syntax is equal to the syntax defined in the documentation of the
multiplicityproperty.- Type
str
-
property
stereotypes¶ The setter takes a single or a list of
CStereotypeobjects which extend this association. Extension is only possible, if this association is an association between meta-classes. The getter returns the stereotypes that extend this association.- Type
CStereotype|list[CStereotype]