Association (object-oriented programming)

An association (English Association) is a model element in the Unified Modeling Language ( UML), a modeling language for software and other systems.

An association describes a relationship between two or more classifiers, in the most common case, a connection between exactly two classes. Associations thereby define a relationship at the type level. On the instance level, the concrete expressions of an association link name.

In addition to classes, however, any other classifier ( for example, interfaces or applications ) via associations are related to each other.

The ability to participate in more than two types of association, is rarely used. The association is in this case called n-ary association and is represented by a diamond, abut the n objects to the leading lines. The association in UML is similar to the relationship type in the Entity -Relationship Model, in which case detail differences exist, which at first sight not easily recognizable, but in practice are of great importance indeed (see Object - relational impedance mismatch). In principle allowed, although not usual, the presentation is with hash key associations with only two association ends, causing the appearance of Chen notation of entity-relationship models is similar.

An association is called reflexive if it connects a classifier with itself. The two ends of the association so here show the same type. In the figure on the right is the association " father / son relationship " reflexive.

Association ends

Graphically, an association is represented by a line. This equation is based suggest that the ends of an association are not easy graphical points, but separate model elements. In contrast to the UML 1.4 but there is no model element association end ( association end) more, because the end of an association is modeled since UML2 with the model item property (Property ).

In the figure on the right is shown by an example that the repository model stores an association end as an instance of the metaclass Property behind the class diagram. Association ends can therefore have all the characteristics of a property:

  • You can have a multiplicity, expressed by a lower and an upper limit in the form lowBound .. upper limit.
  • You can have a name.
  • You can declare a visibility.
  • You can specify whether the association end is sorted ( ordered ) or unique ( unique).

An association forms a kind of bridge between two types: one starts at the instance of the type involved one can navigate through an object relationship to the instance of the second type. The UML2 now allows to limit the navigability of association ends. It shall distinguish three types, such as the navigability can be set:

Associations that are navigable on both sides are called bi-directional associations, corresponding unidirectional only at one end navigable associations.

The example at left shows two associations between the same types. Because they have different names billing address and delivery address for, they can be distinguished. The two small triangles assist the reader. They indicate the reading order for the name of the association, here, for example, address [ is ] the billing address for your order. About an order, two different instances of address belong, which are distinguished by their role. The instance has a delivery address the role of other, optional, billing address the role.

Aggregation and composition

If you now wish to highlight an association end or strengthen the bond of association, so are an aggregation and composition as a means of disposal.

In the graphical representation of an Aggregation a non- filled diamond marks the end of which is connected with the whole. In the special case of composition, it is a filled diamond.

Aggregation

An exact definition is not given in the UML2, but it is pointed out that aggregation varies by application and modelers. A concrete benefits can be derived, for example, by letting have a special emphasis on one end of an association.

Basically, the distinction between association and aggregation is difficult. A faint indication of the meaningful use of an aggregation appears to be the presence of Transitivitäten between the modeled classes. That is, when the time between A and B, there is a part-whole relationship and also between B and C, then A must also be a part of C.

A special type of aggregation and anwendungsträchtigere is the composition.

Composition

The composition (composite aggregation or composition ) as a special case of aggregation also describes the relationship between a whole and its parts. The difference in aggregation is that the existence of an object that is part of a whole, depends on the existence of the whole.

An object can always just part of a whole be maximum (multiplicity 0 to 1 or 1). Rooms there are, for example, in a building or on a barge. The use of a composition then says that a concrete room is located either in a building or on a barge. The existence of an object may not be dependent on just two different objects at the same time.

Existence dependency means that the whole life cycle of the parts determined, that is, the object that represents the whole, also takes on the responsibility for the life of the objects that represent its parts. If the whole thing cleared away the objects that were part of at this time. Blasts to a building or a residential ship sinks ( we see a possible rescue from ), the spaces will be destroyed with it.

An object that is part of a whole which can be used for life time switch to another whole, or even entirely granted independence. In Building example, that would be a container building. If a container is broken down buildings, residential containers are independent of other objects. You can then also exist alone. Only when you configure it to a container building, they are existence dependent again.

A composition describes an acyclic, directed graph ( Whole ← ← part subpart ). As a relation is asymmetric and transitive.

Differences to the UML 1.4

The UML2 has introduced the notation for the navigability of association ends.

In UML 1.4, there was a special model element AssociationEnd, which was in the UML2 replaced by Property.

84260
de