On this page
Building a Class Diagram Report
In this exercise, you will learn how to create a simple Class Diagram report. A Class Diagram report must contain the following information:
- A class diagram's name.
- A diagram.
- A table that describes the class (we will call it a class description table) based on the diagram shown below.
The table must have the following structure:
Class Name
Documentation:
Attributes
Attribute Type 1
Name
Attribute Type 2
Name
Attribute Type 3
Name
Attribute Type 4
Name
- The layout of the report should look like the example below.
The layout of a basic class diagram on the diagram pane.
Instructions
The first and most important step in creating a report is setting up the document and its layout.
- Open Microsoft Word.
- Create a table that will be used as the basic layout for a class description table.
The layout for a class description table in a Word document containing the name of the class, the attributes, and the relationships.
As shown in the preceding figure, a diagram will appear at the top of the report followed by a class description table. Accordingly, each diagram on the Class diagrams list has a class description table describing each component in the diagram. Follow the next steps to create the document template:
Iterates through a list of diagrams.
- Print the diagram and its name.
- Get a list of class elements that are displayed in the diagram.
- Iterate through the list of class elements.
Create a class description table for each class element in the list.
The steps listed above contain two #foreach loops: the outer loop that iterates through a list of diagrams, and the inner loop that iterates through a list of Class elements. The list of diagrams in a MagicDraw project is represented by $Diagram.At the top of the page of the word document type:
#foreach ($diagram in $Diagram) **Codes in between ** #end
$Diagram is a list of all the diagrams in a MagicDraw project. This means that a project will be in the list if it contains more than one type of diagram. To filter out other types of diagrams, add the #if directive with a conditional statement to test whether or not $diagram is a class diagram:
Next, you need to get all the elements contained in the diagram by using $report. $report is a standard tool containing helpful methods such as getDiagramElements() that returns a list of elements inside a diagram.
In the example above, $eList has been assigned with a list of Elements inside $diagram. Now, you need to create an inner loop that will cover the table that you created earlier, and then filter out the elements inside the diagram whose type is not Class element.
Enter the information of the class in the table by calling its attributes, etc.:
The Class Name and Documentation values are obtained by referencing the name and documentation attributes of $e.
Use the #forrow directive as the attribute to print rows of the class attribute type ($att.type.name) and the class attribute name ($att.name).
Save the file as Rich Text Format. Open MagicDraw and draw a simple class diagram.
A simple class diagram.
Add the template to Report Wizard, and generate a class diagram report using this template. The following figure shows the result of the generated report.
The generated report of the class diagram in the Word document.
Glossary
- Class diagram
A class diagram is a diagram in which the primary symbols in the contents area are class symbols.
More information about working with report templates using Report Wizard
To learn more about working with report templates, visit the following pages:
Creating a report including the Actor, Use Cases, and diagram image names