Amway an IDEA Sao operation: a sequence diagram of one-click generation method

Python combat community

Java combat community

Long press to identify the QR code below, add as required

Scan QR code to follow to add customer service

Enter the Python community▲

Scan QR code to follow to add customer service

Enter the Java community

Author丨Guide

Source丨JavaGuide (ID: JavaGuide)

In our usual study/work, we often face the following scenarios:

  1. Read other people's code

  2. Read the frame source code

  3. Read the code you wrote a long time ago.

Don't think that work is just writing code. In actual work, you will find that most of your time is actually spent reading and understanding existing code.

In order to understand the calling relationship between objects faster and more clearly, I often need to use sequence diagrams. Hand animation sequence diagram is still very troublesome and time-consuming, but IDEA provides a plug-in called SequenceDiagram to help us solve this problem. Through the SequenceDiagram plug-in, we can generate sequence diagrams with one click.

What is a sequence diagram?

There are many definitions of sequence diagrams on the Internet, and I think they are not easy to understand and too abstract. The most amazing thing is that most of the articles have exactly the same definition of sequence diagrams. It seems that everyone has given full play to the "essence" of writing code!

Let me simply talk about my understanding! However, to be honest, I am not very clear about Sequence Diagram myself. Please point out any problems and areas that need to be improved in the following description.

Sequence diagram (Sequence Diagram), also known as sequential diagram , is a UML behavior diagram. Represents the sequential calling relationship between objects when the system executes a certain method/operation (such as login operation).

This sequence call relationship can be understood as follows: you need to execute the method/operation login provided by an object a in the system, but this object relies on the method getUser provided by the object b. Therefore, here is the a -> b call relationship.

Let me give you two more examples!

The following figure is a sequence diagram of the business process of WeChat Pay. This figure describes the relationship between basic payment and payment sequence in WeChat payment related roles (customer, merchant...) in the WeChat payment scenario.

img

The following figure is a sequence diagram of executing a method in an HTTP framework I wrote. This diagram depicts're calling the InterceptorFactoryclass loadInterceptors()to call the relationship between classes when the methods involved.

In addition, the domestic generally prefer to call the sequence diagram "sequence diagram".

  • If you look at it from the perspective of pure translation, the word sequence does not mean "time", only sequence, order, etc., so some people say that the term "sequence diagram" is not accurate.

  • From a definition point of view, the description of the timing diagram is no problem. Because the trigger timing of each message in the Sequence Diagram is indeed executed in chronological order.

I think it’s okay to call Sequence Diagram a sequence diagram or a sequence diagram, so don’t be too entangled.

In which scenarios do you need to view the sequence diagram of the class?

We need sequence diagrams in many scenarios, for example:

  1. Reading the source code : When reading the source code, you may need to check the calling relationship of the related classes involved in the calling target method. Especially when there are many calling levels of the code, it is very useful for us to understand the source code. ( Digression: In actual work, most of our time is actually spent reading and understanding existing codes. )

  2. Technical documentation : When we are writing project introduction documents, in order to make it easier for others to understand your code, you need to generate sequence diagrams for related classes based on core methods to show their calling relationships.

  3. Sort out the business process : When our system business process is more complicated, we can visualize the relationship between the important roles and objects involved in the system through the sequence diagram.

  4. ......

How to use IDEA to generate sequence diagrams based on the methods in the class?

Through the SequenceDiagram plug-in, we can generate sequence diagrams with one click.

And, you can also:

  1. Click the class/method in the sequence diagram to jump to the corresponding place.

  2. Delete the corresponding class or method from the sequence diagram.

  3. Export the generated timing diagram to PNG image format.

installation

We can find this plug-in directly in IDEA's plug-in market. I have already installed it here.

If you cannot use the plug-in market that comes with IDEA due to network problems, you can also download and install it manually through the official website of the IDEA plug-in market.

Simple to use

  1. Select the method name (be careful not to select the class name), then click the right mouse button and select the Sequence Diagram option!

  1. After configuring some basic parameters of the generated sequence diagram, such as call depth, we click ok!

You can also locate the relevant code through the generated sequence diagram, which is especially helpful when we read the source code!

After the timing diagram is generated, you can also choose to export it as a picture.

程序员专栏 扫码关注填加客服 长按识别下方二维码进群

Recommended recent exciting content:  

 Comparison of programmer income in China, the United States, Japan and India

 A sad day for programmers

 SringMVC from entry to source code, this one is enough

 10 Python visual animations, carefully and beautifully


Watch the good article here to share it with more people↓↓

Guess you like

Origin blog.csdn.net/Px01Ih8/article/details/109301888