The difference between association and aggregation

I understand the difference between aggregation and composition, but I'm struggling a bit with association. My real understanding is that there is an association between classes when they use each other, for example, one object is passed to another during a method call. See also:

http://www.codeproject.com/Articles/330447/Understanding-Association-Aggregation-and-Composit

Both objects exist independently of each other and, unlike aggregation, neither object is a container class of the other. Does this mean that both objects MUST have a copy of the other (s) (for example, a 1: m relationship) or how the association is still preserved. Any feedback would be greatly appreciated.

+8
source share
8 answers

From the UML 2.4.1 add-in:

The association announces that there may be links between instances of related types. A reference is a tuple with one value for each end of the association, where each value is an instance of the end type. (UML Superstructure, Page 37)

Nothing more, nothing less. and very vague. Because of this, it is also very difficult to understand. What I defined (in the course I teach) is a hierarchy of links from dependency to composition, where:

  • Dependence from A to B means that A uses B , but indirectly (say, getting its instances and sending them to other objects).
  • The association from A to B means that A directly uses B (for example, by calling methods)
  • Aggregation from A to B means that B is part of A (semantically), but B can be shared, and if A deleted, B not deleted. Note that this does not say anything about how the "part" is implemented.
  • Composition A to B is similar to aggregation, where B cannot be shared, and if A removed, all of its aggregates ( B s) are also removed.
+11
source

Aggregation is an associative relationship in which the Association can be considered as the containing class of the "Ownership" class, and the lifetime of this relationship is not defined.

Association is a Has-A relationship.

Example: -

  public class Person { private final Name name; private Address currentAddress; //... } 

In this case, the person’s name is Has-A and Has-A Address, so there is an association between the person and name, as well as the person and address.

+3
source

An association describes the relationship between instances of one or more classes. In the words of the UML Reference Guide, "Associations are the glue that unites the system."

Aggregation is a form of association in which the relationship of the “whole part” exists. You can say that if the Airplane class has an Engine class, then this forms an “integer” relationship.

+2
source

Aggregation

Let the terms be given. Aggregation is a metaterm in the UML standard, and means BOTH composition and general aggregation, simply called shared. Too often, it is incorrectly called "aggregation." This is BAD, and the composition is also aggregation. As far as I understand, you mean that you understand "general aggregation and composition."

From the UML standard:

The exact semantics of general aggregation depends on the application area and the fashion designer.

I did not find a word about this totality of the alleged plurality, for example.

Association.

Definition from the UML 3.4.1 standard:

An association describes a set of tuples whose values ​​refer to typed instances. An instance of an association is called a link. A reference is a tuple with one value for each end of the association, where each value is an instance of the end type.

An aggregated relationship is a subclass of an association.

The association is based on relationships. IT is the glue for models.

But your feelings did not lie - since the general aggregation is not strictly defined, there is also no strictly defined border between the Association and the Associated Association. The authors of the tools and fashion designers themselves must establish this.

+1
source

Association

It is a relationship between two or more objects, where all objects have their own life cycle, and there is no owner. The name of the association determines the nature of the relationship between the objects. This is represented by a solid line.

Let's look at an example of the relationship between Teacher and Student. Several students can communicate with one teacher, and one student can communicate with several teachers. But there is no property between objects, and both have their own life cycle. Both can be created and deleted independently.

Aggregation

This is a specialized form of Association, where each object has its own life cycle, but there is property. This is a “whole or part” relationship. It is represented by a hollow diamond followed by a line.

Let's look at an example of the relationship between the Department and Teacher. A teacher can belong to several departments. Therefore, Teacher is part of several departments. But if we remove the Department, the object of the Teacher will not destroy.

+1
source

It depends on the context.

Association : a man drives a car, focuses on the relationship of the caller and the callee.

Aggregation : a person has a car, focusing on relations with the owner and participant.

Composition : a person has a mouth, focus on the owner and participant, but the owner consists of participants, which means that they have a common life cycle.

I feel like I'm speaking Chinglish.

+1
source

association

Association is a relationship in which all objects have their own life cycle, and they do not have an owner. Let’s take an example of a Teacher and a Student. Several students can communicate with one teacher, and one student can communicate with several teachers, but there is no property right between the objects, and both have their own life cycle. Both can create and delete independently.

aggregation

objects in the Aggregation have their own life cycle, but there is property. A child cannot belong to another parent. Let's take an example of a pulpit and a teacher. One teacher cannot belong to several departments, but if we remove the teacher, the object will not be destroyed. We can think of an “eat” relationship.

Composition

This is a strong type of aggregation. A child object does not have its life cycle, and if the parent object deletes all child objects, they will also be deleted. Let us again take an example of the relationship between the House and the rooms. A house can contain several rooms, there is no independent living room, and any room cannot belong to two different houses, if we delete the house, the room is automatically deleted.

+1
source

The relationship between types of objects classifies the relationships between objects of these types. For example, the association Committee -has- ClubMember -as-chair, which is visualized as a join line in the class diagram shown below, can classify the relationships financed by the Finance Committee-has-PeterMiller-as-chair, RecruitmentCommittee - has -SusanSmith-as- chair and AdvisoryCommittee-SarahAnderson-as-chair, where PeterMiller, SusanSmith and SarahAnderson objects are of type ClubMember , and FinanceCommittee, RecruitmentCommittee and AdvisoryCommittee objects are of type Committee .

The association Committee-has-ClubMember-as-chair

See also my alternative CodeProject article .

0
source

All Articles