Controlling the Representation of Associations

There are five uses of lines which AgileJ StructureViews recognises:

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.

import java.util.Hashmap;
import java.util.Map;
import java.util.ArrayList;


public class SingleSourceClass {
	Associate associate;
	
	/** @aggregation */
	Aggregate aggregate;
	
	/** @composition */
	Composite composite;
}


class ArraySourceClass {
	Associate[] associates;
	
	/** @aggregation */
	Aggregate[] aggregates;
	
	/** @composition */
	Composite[] composites;
}


class MultiSourceClass {
	/** @association Associate */
	Map associates;
	
	/** @aggregation Aggregate */
	ArrayList aggregates;
	
	/** @composition Composite */
	Hashmap composites;
}


class Aggregate {
}


class Associate {
}


class Composite {
}

 

SingleSourceClass

By default an association line (with a cardinality of 1) 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.

ArraySourceClass

The field types are all arrays, so the lines are annotated 0..*. The @aggregation and @composition tags still modify the line the same way.

MultiSourceClass

If a class name is supplied after the tag, the relationship is assumed to be implemented via a container. The line is drawn to the named class, and the line is annotated 0..* because the use of a container is assumed to represent a one to many relationship.