Layla
Layla

Reputation: 5446

is this a case of association or aggregation?

I have found a Java example about how students register in a set of courses:

Student-----takes------Courses

and in the example is defined as Association, but why it cannot be Aggregation? for what I see each class could exist independently. How do differentiate both?

In the above example I am dealing with the schema that a Student has an array of Courses as attribute, and Course has an array of Students within it also; so in that case is association because both of them are related, and aggregation because one is contained inside the other?

Upvotes: 0

Views: 248

Answers (4)

Gangnus
Gangnus

Reputation: 24464

You should define the names first.

What is Courses? The subject? Or the subject+lector? Or the subject+lector+classroom/time?

Let's name them Subject, Courses, Classes

And we have Lectors, Classrooms, Students.

Here is the diagram. (please, notice, that no arrors on a connection means that connection is navigable in both sides)

enter image description here

So, the connection Student-Courses HERE is many to many dependency. You can implement it by having aggregation (lists, for example) on both sides, or on one of them. The first variant is harder to change, but easier to read. But you HAVE to have an aggregation at least form one side.

Upvotes: 0

Steph
Steph

Reputation: 2049

To put it very simply, an aggregation represents containment, where the content can be removed from the container and exist on its own (when it can't, it is a composition).

Here it is not a containment, students are not contained in a class, and classes are not contained in a student. Thus, it is a simple association

2 comments:

  • When an object is contained in another, it can't be contained in several others. Thus, for an aggregation, multiplicity will be 1 or 0-1 on the container side. Here, it is 0-* on both sides, which can never be an aggregation.
  • An aggregation is just a special case of association, so anyway, if you make an association, you will always be right (though in some cases not very precise)

Upvotes: 0

Bruce
Bruce

Reputation: 2310

This is not aggregation since a course is not a collection of students and a student is not a collection of courses. This is a simple many-to-many association. I have also seen this modeled with an association class "enrolls" which encapsulates the methods and data necessary to allow a student to sign up for a course. An example of aggregation would be how a car exists in a body shop application. The car has removable parts (tires, engine, chassis, etc.) which can exist independently but it would be useful to know which parts still exist on a particular car.

Upvotes: 1

observer
observer

Reputation: 3005

UML knows different (sub-) types of associations, and the aggregation is just one of them. An association just means that there is some kind of relationship between source an target.

What you probably mean instead is the difference between an aggregation and a composition. In an aggregation, the aggregated entities can exist without the whole; while in a composition, they cannot.

Upvotes: 0

Related Questions