0

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?

Layla
  • 5,234
  • 15
  • 51
  • 66
  • It is technically correct to be both Association and also Aggregation. Note that aggregation, like composition, is just a special case of association. – Ronald Jan 21 '14 at 11:45

4 Answers4

1

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.

Bruce
  • 2,230
  • 18
  • 34
  • You are mixing aggregation and composition. It is the last that is or contains a collection of... – Gangnus Jan 20 '14 at 09:15
0

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.

observer
  • 2,925
  • 1
  • 19
  • 38
0

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)
Steph
  • 1,989
  • 14
  • 18
0

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.

Gangnus
  • 24,044
  • 16
  • 90
  • 149