This question has been, and will be, asked many times in many different variants, because many people, including many high-profile developers, are confused about the meaning of these terms, which have been defined in the UML. Since the question has been asked many times, it has also been answered many times. See, e.g. this answer. I'll try to summarize the UML definitions.
An association between two classes is not established via a method parameter, but rather via reference properties (class attributes), the range/type of which are the associated classes. If the type of a method parameter is a class, this does not establish an association, but a dependency relationship.
It's essential to understand the logical concept of associations first, before looking at how they are coded. An association between object types classifies relationships between objects of those types. For instance, the association Committee
-has-ClubMember
-as-chair, which is visualized as a connection line in the class diagram shown below, may classify the relationships FinanceCommittee-has-PeterMiller-as-chair, RecruitmentCommittee-has-SusanSmith-as-chair and AdvisoryCommittee-has-SarahAnderson-as-chair, where the objects PeterMiller, SusanSmith and SarahAnderson are of type ClubMember
, and the objects FinanceCommittee, RecruitmentCommittee and AdvisoryCommittee are of type Committee
.
An association is always encoded by means of reference properties, the range/type of which is the associated class. For instance, like so
class Committee { ClubMember chair; String name;}
In the UML, aggregation and composition are defined as special forms of associations with the intended meaning of classifying part-whole-relationships. In the case of aggregation, as opposed to composition, the parts of a whole can be shared with other wholes. This is illustrated in the following example of an aggregation, where a course can belong to many degree programs.
The defining characteristic of a composition is to have exclusive (or non-shareable) parts. A composition may come with a life-cycle dependency between the whole and its parts implying that when a whole is destroyed, all of its parts are destroyed with it. However, this only applies to some cases of composition, and not to others, and it is therefore not a defining characteristic. An example of a composition where the parts (components) can be detached from the whole (composite) and therefore survive its destruction, is the following:
UML navigability
whileUML aggregation
is about "whole/part relationship" – Sanctimonyaggregation: AggregationKind
determines the type. See "Figure 7.12 - Classes diagram of the Kernel package" inwww.omg.org/spec/UML/2.4.1/Superstructure
. If you need to use a "list" to hold the "reference" is determined byUML multiplicity
. If the association is notUML navigable
then there will be no "reference" at all. Some of the terms are orthogonal and some are special cases (subclasses). I'd recommend you to pick one good book (e.g. uml-diagrams.org) and use it to do something – SanctimonyDepartment-Course
andDepartment-Professor
areUML associations
. At the same time both associations can be marked asUML aggregations
(maybe even asUML compositions
depending on the "business rules" at the particular university) – Sanctimony