codeable_models.CAssociation

class codeable_models.CAssociation(source, target, descriptor=None, **kwargs)

CAssociation is used for representing associations. Usually associations are created using the association method of CClassifier which calls the constructor of CAssociation to actually create the association (i.e., CAssociation could 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, CAssociation accepts: 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 property multiplicity for 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 property multiplicity for 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 to True, it sets the property composition to False.

    • composition:

      Takes a boolean argument. If set to True, this association is set to be a composition, else it is not. Also, if set to True, it sets the property aggregation to False.

    • stereotypes:

      Takes a single or a list of CStereotype objects 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 name property derived from CNamedElement is interpreted as the label of the association.

Descriptor Syntax:

The descriptor has 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 multiplicity property, 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..1 to * association from a class cart to a class item labelled in cart with source role name cart and target role name item 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 CAssociation are shown in the figure below.

../_images/association_model.png

A CAssociation is need in order to derive CLink objects, which link objects in an object model. The CAssociation is the classifier of the CLink.

As can be seen, a CAssociation can be extended by stereotypes. A CLink can have stereotype instances of any CStereotype defined on the link’s association.

The CClassifier can be introspected for its associations. The association stores its source and target classifiers.

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 to True, it sets the property composition to False.

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 to True, it sets the property aggregation to False.

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 classifier is the target, and vice versa. Raises an exception if classifier is 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

CClassifier

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 range 0..*.

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 multiplicity property.

Type

str

property stereotypes

The setter takes a single or a list of CStereotype objects 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]