Add UML diagrams to the JavaDoc

It is possible to add UML diagrams to the JavaDoc generated during the build phase.

The first thing to do is to install Graphviz which is an open source graph visualization software.
After installation, add the bin folder (D:\Graphviz\bin for instance) to the PATH environment variable.
Then configure the pom.xml :

<build>
		<plugins>
			<plugin>
				<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-javadoc-plugin</artifactid>
<version>3.0.1</version>
<configuration>
<doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
<docletartifact>
<groupid>org.umlgraph</groupid>
<artifactid>umlgraph</artifactid>
<version>5.6.6</version>
</docletartifact>
<additionalparam>-views -all</additionalparam>
<doclint>none</doclint>
<usestandarddocletoptions>true</usestandarddocletoptions>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
			</plugin>
		</plugins>
	</build>

Here i chose to add the maven-javadoc-plugin to the build maven phase. In the configuration of the plugin, i added the UmlGraphDoc doclet.
UMLGraph allows the declarative specification and drawing of UML class and sequence diagrams.

Run mvn install and then check the generated JavaDoc under the folder target/site/apidocs/
Here is a sample :

The code of this project is available on my github repository :
https://github.com/longbeach/eclipseumlgraph

Aggregation and composition in Java

I usually forget the differences between the composition and the aggregation relationships and mix them together, so here is a memento that i will share with everyone.

  • Composition : a filled diamond
  • Aggregation : an unfilled diamond

The relation between a car and a tyre is an aggregation because the tyre is still a tyre if it is not attached to a car. The tyre has a life of its own. It exists outside of a car and you can use it on another car.

The relation between a car and a carburetor is a composition because the carburetor has no use if it is out of a car.

Aggregation and composition in Java

Now more interesting is the implementation in Java of these 2 relationships :

Aggregation :

class Car {


}

class Tyre {

private  car = new Car();


}

Composition :

class Carburetor {


}

class Car{
Carburetor  carburetor = null ;
public void setCarburetor( Carburetor  carburetor )
{
this.carburetor = carburetor;
}


}