1. What is UML
UML class diagrams can quickly examine the structure of a code.
2. Theme
The use of UML class diagrams in Pycharm.
3. Preparatory work
(1) Pycharm version 2.7 or higher
(2) Installing the Python Interpreter
(3) UML plug-in and UML class diagram plug-in installation and normal use
4. Prepare an example
Create a Animals module and a mammal.py file (Alt+insert→python package, Pythonfile) and enter the following code:
Continue to add more classes to them, such as carnivore and herbivore.
5. Browse program structure by UML class diagram
Suppose we want to see the derived structure of mammals, in the Project tool window, right-click mammal.py, point to diagrams node on the shortcut menu, and select the following commands available:
(1) Show Diagram: Open UML Class diagram in the current editing tab
(2) Show Diagram Popup: Display UML class diagrams in a separate window
Select a class in mammals (for example, marsupials) to view it with a UML class diagram:
You can also use the shortcut key Ctrl+alt+u (current window) or ctrl+alt+shift+ U (stand-alone window).
Click and button to view details:
You can also use the shortcut menu:
See the class Diagram Toolbar and Context menu page for more functions for toolbars and shortcut menus.
Next, add a comment to it. Select the element you want to annotate and press Alt+insert:
Enter the comment content:
Click OK to add the comment:
6. Navigation between structure diagram and source code
How do I jump from a structure diagram to the source location of the response?
Select a node element in the structure diagram, press F4 or right-click on the shortcut menu to select the jump to Source command:
7. UML Structure diagram function
8. Find All References
Select a node element in the structure diagram, right-click, select Find Usages in the shortcut menu, or use the Alt+f7 shortcut key:
9. Refactoring
You can refactor (rename, and so on) the class or member directly in the class diagram.
In the class diagram, right-click the node you want to modify, point to the Refactor command, and select the corresponding command in the submenu.
For example, if you want to rename a class, you need to select it in the class diagram and then select the Refactor→rename shortcut menu command or press SHIFT+F6:
10. Adding elements to the model
Press space to enter the type and name in the popup window:
Add Carnivore:
Next, manually create more classes, such as carnivore or herbivore, to specify the mammal type. For example Cow inherited the herbivore and Eutherian. Tiger inherits the Carnovire and Eutherian. Duckbill inherited the herbivore and marsupial,tasmaniandevil inherited the carnivore and marsupial:
Press space to add these classes to the class diagram:
Click the button to optimize the display style:
11. Removing elements from class diagrams
Select an element in the class diagram, Delete:
The deleted class still exists in the source code, but is not visible in the class diagram:
12. Browse code changes by class diagram
It is recommended to use Ctrl+alt+shift+d shortcut keys, or buttons.
The most complete pycharm tutorial (--pycharm) The UML class diagram of the extended function is used