Controlling the Representation of Associations

There are five uses of lines which AgileJ StructureViews recognises:

  • inheritance
  • dependence
  • association
  • aggregation
  • composition

Inheritance and dependence lines can unambiguously be deduced from Java source. Association, aggregation and composition are more difficult to determine because they are separate design intents all of which are implemented the same way in Java. To make matters worse, you may be viewing code which was written prior to Java 5 which used containers of java.lang.Object, from which the contained type cannot be deduced. By default AgileJ StructureViews treats all fields as association.

To direct AgileJ StructureViews to represent aggregation and composition add a Javadoc tag (@aggregation or @composition)declaring the type of association and the target type. Note that the @association tag on Owner has no effect but you can add it if you want to be explicit.

public class Car{
  /** @aggregation */
  private Wheel[] wheels = new Wheel[5];
  /** @composition */
  private ChassisIdentifier identifier;
}

public class Owner{
  /** @association **/
  private List<Car> cars;
}

 

SingleSourceClass

By default an association line is drawn if the field type exists on the diagram. Marking a field with the @aggregation or @composition tag changes the way the line is drawn.

  • An association line is drawn automatically from Owner to Car.
  • The tag @aggregation causes an open-diamond line to be drawn.
  • The tag @composition causes a solid-diamond line to be drawn.