Return to index

UML - Java

 

UML ('Unified Modelling Language') provides a graphical means of representing a high-level view of a software program.

UML can be used to describe an existing program or, better still, used to design a new program - by starting with the high level view, the structure of the software can be optimised before the implementation details are later filled in (in practice, sometimes the structure will be changed after some details are filled in, and this is ok, if not ideal).

A UML description of a software program is like the plan that an architect designs - that is later implemented by builders to give a finished building.

By high level structural view is meant the classes to be used and their relationships to each other; later, method signatures can be added - the public methods that a class or interface presents to other classes. Later still, the implementation details of these methods (in the case of classes) can be coded in the Code View, using private methods to provide 'sub-routines' as required.

TJI provides 'round-trip' UML-Java functionality such that the UML View and the Code View are automatically synchronized. This means that you can work on either view at any time and the other view is updated to match automatically. You can start with existing code or start a UML design from scratch.

TJI's approach is dialog based with automatic class diagram generation. That is, classes and interfaces can be added by being specified in a dialog; the appropriate relationships ('extends' and 'implements') are shown in the class diagram automatically. 'Uses' relationships are shown when automatic analysis of the implementation details (i.e. the source code) indicate this relationship between classes.

 

Using the UML View

To start a new design in the UML view, first create a new empty project. If you have existing source code, the corresponding UML class diagram will be shown when the UML view is opened or selected.

To add classes and interfaces, click on the 'Add New ...' buttons at the top of the UML tab. Specify the class/interface name and any 'extends' and 'implements' relationships required. Any classes/interfaces specified are checked to avoid typos - that the classes/interfaces specified as relationships exist in the project or are standard Java classes/interfaces.

TJI also checks for the following errors :

  • a class implementing a class
  • a class extending an interface
  • an interface extending a class
  • an interface implementing an interface

In the event that you want to specify a class/interface that you have not yet defined, choose 'proceed anyway' to go ahead with adding the new class/interface. When a new class or interface is created in the UML view, a new Java source code file is created and added to the current project. In the case of a new class, a default (no parameters) constructor is added. You can then add other constructors if you wish.

To remove a class or interface, first select it by clicking on the appropriate class/interface in the UML diagram so that a details frame becomes visible, or select the appropriate details frame from those that are open. Then click on the 'Remove Class/Interface' button at the top of of the UML tab and confirm its removal. Note that the corresponding code will also be removed from the project (but not deleted from your file system if it has been saved - you may wish to make use of this code later).

To add a method to a class or interface, first select the class or interface as described above. Then click the 'Add Element' button on this frame. Choose to add a 'Method' and define the method using the dialog that will then appear by specifying the return type, method name and any parameters required. If no return type is specified, a return type of 'void' is used. The new method will then be shown in the details frame. In the code view, the method signature is added to the corresponding class/interface Java source file.

You can add a constructor, field or inner class in the same manner as above.

To delete any element (field, method, constructor or inner class), select the element and then click on the 'Edit Source Code' button and manually remove it from the source code.

To write or edit the implementation details for a method, constructor or inner class, or add code comments to any element, select the element and then click on the 'Edit Source' button of the details frame. You will be taken to the source code view with the selected element shown ready for editing.

Alternatively, simply double-click on a field, method or inner class to jump to that element in an editor. The source file will be opened automatically if it is not already open.

The UML view automatically updates to reflect changes made in the source code view. However, if you wish to force an update to the UML view, click on the 'Refresh' button at the top of the UML tab. The 'Refresh' button can also be used to simply redraw the diagram, possibly creating a more pleasing arrangement of the classes and interfaces.

The 'Private' checkbox lets you choose whether to show private fields and methods in the class details frames.

You can select which relationships to include in the class diagram by selecting or deselecting the relationships - these checkboxes are at the top of the frame.

You may open any number of class and interface details frames. You can use the Escape key ('Esc') to close a currently in-focus details frame.

 

Return to index