javac#oopumlobject-oriented-analysis

UML association that is not an aggregation or composition?


Can someone give a code example of an association UML relationship (one way arrow ->) that is neither an aggregation nor a composition?

I understand that aggregation and composition are types of associations, but I cannot think of an association relationship that is not an aggregation or a composition.

Can the following code be just an association relationship from A->B, but not aggregation or composition under certain conditions?

import B;
public class A {
  private B b;
}

Solution

  • According to Robert Martin:

    An Association represents the ability of one instance to send a message to another instance. This is typically implemented with a pointer or reference instance variable, although it might also be implemented as a method argument, or the creation of a local variable.

    The code:

    public class A {
      private B b;
    }
    

    can represent either association, aggregation or composition. It represents a mere association as long as A doesn't have a "HAS-A" relationship with B. For instance, the following could be an association, but not an aggregation or composition relationship.

    public class Vehicle {
      private Person owner;
    }