Generate Class Diagram from Existing Classes

When creating a class diagram, sometimes we would draw it using the diagram toolbar and there are times we would reuse elements by drag & drop. However, when you start from scratch, sometimes it can be difficult to know which class goes with which because we may not necessarily know all relationships among them.

Luckily, there is a function called Form Diagram which automatically generates a class diagram from existing classes for you. You just need to specify one or more classes that you want to explore with.

This article will show you how.
Note: Visual Paradigm for UML (VP-UML) is used in the example below.

Before We Start

We have already reversed Java code for java.io & java.lang and you can see them in the Class Repository.

Reversed Java Code Shown in Class Repository

Reversed Java Code Shown in Class Repository

Steps To Take

Let’s say we want to take a closer look at the File class.

1. In the Class Repository, under base > java > io, right click on File.

Select java io file class

Select java io file class

 

2. While right clicking on File, select Form Diagram.

Under it there are 3 choices to select for your class diagram as follows:

– Customize… allows you to customize your own class diagram.
– Hierarchical diagram shows you the vertical structure of classes (e.g. a superclass over another).
– Navigation diagram shows you the horizontal structure of classes (e.g. which has associations with which).

3 Choices Under Form Diagram

3 Choices Under Form Diagram

 

3. Let’s say we’ve selected Customize…

In the Form Diagram dialog box, under the Form Diagram tab, the preview changes based on the current mouse location (e.g.  Generalization, Association).

Form Diagram Tab

Form Diagram Tab

 

4. In the Form Diagram dialog box, under the Presentation Options tab, the preview changes on the current mouse position (e.g. Attribute Options).

Select the checkbox next to Show operation signatures. Click OK.

Presentation Options Tab

Presentation Options Tab

5. Click Yes to set the first view as the master view.

Set it as Master View Dialog Box

Set it as Master View Dialog Box

6. Your customized class diagram will then appear.

Customized Class Diagram Generated

Customized Class Diagram Generated

Related Articles

Related Links

2 replies
  1. Rain Wong says:

    The Salesforce Apex classes are based on Java and therefore you can make use of the Java round-trip engineering feature (supported in Standard Edition or above) to reverse it into UML Class Model. Details about reverse engineering of Java source can be found at https://www.visual-paradigm.com/support/documents/vpuserguide/276/381/7530_generateorup.html

    After reverse the Java source to class model you can then generate Class Diagram from it. Details can be found at https://knowhow.visual-paradigm.com/uml/gen-class-diagram-from-class/

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply