1
头图

Preface

Just like any living thing, software also has a life process of gestation, birth, growth, maturity, and decay, often referred to as the "software life cycle." The software life cycle is generally divided into several stages: planning, requirements analysis, design, coding, testing, operation and maintenance. The from requirement analysis to design to coding.

Requirements analysis and design occupies two parts of the entire software life cycle, which shows its importance. In many cases, development students often skip these two steps and directly enter the coding stage. This article mainly uses the PlantUML open source project, combined with some actual project requirements for analysis and design.

PlantUML is a simple and easy to understand UML graphics drawing language, a few lines of code can draw various UML diagrams. After being proficient, it can be much more efficient than general drawing tools. The more important point is that it is convenient for version management and can be maintained continuously in the continuous iteration of the functional requirements.

Needs Analysis-Prelude

The prelude is the keynote of a song, which determines the style of the entire song to a certain extent. Requirement analysis is the foundation of the entire software design.

Many development students have questions: Is demand analysis what the product manager wants to do? What matters about our development? In fact, it is not the case. The primary and important purpose of requirements analysis for development is to answer accurately and concisely "Who uses what system to do what". We can usually use "use case diagrams" to clarify this problem.

Use case diagram

For example, in the project of "Posting Orders and Rewards", there are the following use case diagrams:
image - 2021-05-07T181705.416.png

  • "Client-side users use the order-placing system to match the order-placing strategy"
  • "Operations staff use the system to set up the policy of placing orders"

PlantUML code

@startuml

left to right direction

actor operator as D

actor client user as user

Rectangle is polite to post your order (short version) {

D --> (Order Posting Strategy): Set

user --> (post order)

(Order) --> (Order Strategy): Match

}

@enduml

resolve

1. @staruml and @enduml plantuml pre-released start and end tags
2.left to right direction //Identification graphics are drawn from left to right

3. Actor user (villain figure)

4. Rectangle rectangle box, internal code graphics are all in this box

5. --> solid arrow

The above picture simply expresses, "Client users use the order-placing system to match the order-placing strategy" and "Operators use the system to set the order-placing strategy", which can roughly answer "Who uses what system to do what?". But it is not precise enough, we can also do the following extensions:
image - 2021-05-07T181813.499.png

The above figure supplements and explains the "Order Release" and "Order Release Strategy".

  • The entry of "post order" comes from the order list
  • "Ordering strategy" is divided into "setting" and "matching" two actions
  • "Order release" includes "posting dynamics" and "matching order release strategy"
  • "Set a single policy" includes "set incentive type" and "set portrait"

PlantUML code

@startuml

left to right direction

actor operator as D

actor client user as user

Rectangle is polite to post the order (extended version) {

D --> (Set the order placement strategy)

(Set the strategy of placing orders) .> (Set the portrait): "include"

(Set up the order strategy) .> (Set the incentive type): "include"

user --> (View order list)

(View the order list) --> (Post orders)

(Posting list) .> (Posting dynamic): "include"

(Include order) .> (Matching order strategy): "include"

}

@enduml

resolve

1. In addition to commonly used associations and generalizations, use case diagrams have the following two types:
include-a function can be split into smaller parts)
extend-an additional function for a feature
2. (Posting list) .> (Posting dynamic): "include"
It means that "posting" includes the action of "posting dynamic", and it can actually be random text after the colon.

In fact, we can continue to refine the use case diagram, but there is no need to do so. Use case diagrams often only need to be able to describe the two Ws clearly. Who-who will use the system; What-do it with this system What .

Outline design-verse

The main song is the central idea and core theme of a song, which runs through the whole song. In the outline design, we need to sort out and grasp the context of the entire project.

With the foreshadowing of requirements analysis, we can better carry out the outline design. As mentioned above, we need to answer Who&What during demand analysis, while the outline design needs a brief answer to How-How to solve the problem . In the outline design, I usually use UML activity diagrams, state diagrams, and sequence diagrams to describe my design.

Activity diagram

In UML, activity diagrams are relatively broad, such as the flowcharts we often say, swim lane diagrams, etc. can be regarded as a kind of activity diagrams. flow chart is to highlight which process nodes are there, and the direction control of the nodes; the swim lane diagram is based on the flow chart, highlighting the position and role of different roles in the entire process . Usually we will draw together.

Let's look at an example of a self-built circle project:
image - 2021-05-07T190303.093.png

As far as drawing swimlane diagrams is concerned, it is recommended to use other tools for drawing.

Compare the diagrams drawn with other tools (exactly the same process):
image - 2021-05-07T190317.757.png

PlantUML code

@startuml

|Client|

|H5 Frontend|

|ServerAPI|

|CRM background|

|Client|

start

|ServerAPI|

if (does not meet the requirements of building a circle) then

|Client|

: Do not show the entrance to the construction circle;

stop

else

|Client|

: Show the entrance to the construction circle;

|H5 Frontend|

: Fill in the circle creation form;

|ServerAPI|

: Submit the form and wait for review;

|CRM background|

if (failed by audit) then

|ServerAPI|

: The private message notification is not passed;

stop

else

|ServerAPI|

: The private message notification is passed;

|Client|

: Show the entrance to the circle building task;

: Click on the task entry;

|H5 Frontend|

: Display task list;

|ServerAPI|

if (unfinished task) then

: The private message notification task failed;

stop

else

: The private message notification task is successful;

|Client|

: Keep self-built circles;

stop

@enduml

resolve

1. |Client|

Double vertical lines indicate swim lanes.

2、start 、stop

The start and end nodes are necessary elements in the swimlane flowchart.

3、if ... then ... else

Condition judgment is generally represented by a diamond.

4. Generally speaking, the flow in the swim lane can only "swim" all the way down, but cannot "swim" back.

State diagram

State diagrams are used to describe the various states of an entity and the transformation relationships between states. For example, the most common "order status" of the e-commerce platform, the status is complicated and diverse, and the status diagram can be used to express the project more clearly.

In order to have a gift, there is a change in the state of the order list button. In the following example, there are several key points:

-Must have a start state and an end state
-The state is relatively static
-The transition between states must be accompanied by actions
- state that may contain state
image - 2021-05-07T185708.053.png
PlantUML code

@startuml

[*] --> Other order status changes

state Other order state transformation {

[*] --> Waiting for payment

Waiting for payment --> [*]: Cancel payment

Waiting for payment --> Waiting for delivery: paid

Waiting for delivery --> [*]: Cancel order

}

Other order status changes --> rude confirmation receipt: missed polite strategy

Other order status changes --> polite confirmation receipt: hit polite strategy

Receipt is confirmed politely --> Place the order: Click to confirm receipt after 14 days

Rude confirmation receipt --> Posting: Click to confirm receipt

Posting --> View Posting: Release News

Receipt is polite and confirmed --> Receipt is polite: click to confirm receipt

It's courteous to post your order --> View your order: release news

View the posting form --> You are courteous to view the posting form: Send a coupon after approval

You are courteous to view the receipt --> View the receipt: After receiving the coupon

View the posting list--> [*]

@enduml

Analysis

1. [ ] --> and -->[ ]

The sub-tables indicate the start state and the end state.

2、state ... {}

State can contain sub-states. In this example, you do not care about the other status of the order, you can use this grammar to make a simple description.

Timing diagram

The sequence diagram is my favorite UML diagram. In multi-team collaboration, communication can become very efficient, and all relevant personnel can quickly understand where they need to be responsible.

For example, the following figure is a sequence diagram of brand list requirements:
image - 2021-05-07T185743.983.png

PlantUML code

@startuml

hide footbox

autonumber

actor "user" as user

participant "APP" as app

participant "server" as tag

participant "number warehouse" as sc

participant "algorithm" as alg

==Click on the brand entrance==

user -> app: Click on the brand entrance card

activate user

activate app

app -> tag: call self-selected brand data interface

activate tag

tag --> app: return to "No self-selected brand data"

deactivate tag

app -> app: pop up the self-selected brand window

app -> tag: access brand data interface

activate tag

tag -> sc: access data warehouse sorting data

activate tag

activate sc #orange

sc --> tag: return brand sort results

deactivate tag

deactivate sc

tag -> alg: Query user community preference brands

activate tag

activate alg

alg --> tag

deactivate tag

deactivate alg

tag --> app: brand data (including 2 default options)

deactivate tag

app --> user

deactivate app

deactivate user

@enduml

resolve

1、autonumber

Specify the display serial number to facilitate communication and it is recommended.

2、actor,participant

Represents users and objects.

3、activate user,deactivate user

Activate an object, terminate an object.

4、activate sc #orange

Here is a little trick, you can mark the active state of an object with different colors for emphasis.

5. In the small picture on the left, steps 6 and 7 are activated again in an activated state. It can be emphasized here that threads are started and concurrent calls are made.

Detailed design-chorus

The chorus, the so-called important part, is sung twice more carefully. It is the climax part of a song and can sublimate the central idea. In the detailed design, we select some details and core parts from the outline design for further design.

The detailed design is like the chorus part of a song (also often referred to as the climax part). Although it is involved in the verse, it needs to be emphasized. Generally speaking, detailed design is also used to answer How-how to solve problems, but it is necessary to grasp the difficulties of the entire system for key design. I usually use sequence diagrams, class diagrams and component diagrams to describe in UML.

Timing diagram

Seeing this subtitle, some classmates will ask, "Eh, why is it a sequence diagram again?". In fact, the sequence diagram can go up to the calling process at the system level, or down to the calling process at the method level, and can even be very close to the code logic. It is also often used in detailed design. Here is an example, let’s get a feel for it:
image - 2021-05-07T185843.422.png

PlantUML code

...//Omitted

loop loop order ids

server -> extend: Query whether there is an order for trend_extend

activate server

activate extend

extend -> server: return whether the order has been bound

deactivate extend

...//Omitted

alt is courteous when hitting the order

server->cserver: query coupon information

activate cserver

cserver -> server: return coupon information

deactivate cserver

server->result: ``The order is courteous (up to XX yuan)''

else it's polite to miss the order

server->result: ``post order''

end

end

...//Omitted

code analysis

The code on the left only retains the core logic, as follows:

1. loop... end means loop, similar to the while statement in various development languages.

2. alt...else...end represents logical judgment, similar to if else in various development languages.

Class Diagram

Class diagram is a commonly used UML diagram, showing classes, interfaces, and the static structure and relationship between them; it is used to describe the structured design of the system.
image - 2021-05-07T190016.653.png

PlantUML code

@startuml

interface DuDataFlow {

InfoPosts()

InfoAd()

}

class duDataFlow {

grpc.ClientConn

phpservice.Service

context.Context

InfoPosts()

InfoAd()

}

class grpc.ClientConn{}

class phpservice.Service{}

class context.Context{}

DuDataFlow <|-down- duDataFlow

duDataFlow .> grpc.ClientConn

duDataFlow .> phpservice.Service

duDataFlow .> context.Context

@enduml

code analysis

The code on the left is very close to the class definition and interface definition of the development language.

1. <|-down- inheritance relationship

2..> Dependency

other parts

The detailed design is not only timing diagrams and class diagrams, but also modules such as DDL, interface documents, and task division. I won’t go into details here.

At this point, the design document is only one step away from writing the code! !

Conclusion

If you compare writing a software design document to writing a song. Then demand analysis is the prelude of a song, the prelude is the tone of a song, which determines the style of the whole song to a certain extent; the outline design is the main song, the central idea and core theme of a song; the detailed design is It's the climax part of a song, the nice, important part, of course, you have to sing it twice to deepen your memory.

Finally, use a few sentences to summarize the characteristics of several UML diagrams:

-Use case diagram-answer "Who uses this system to do things"
-Activity diagram-highlight the transaction reversal in the process, and the position and role of each lane
state diagram-describes the various states of an entity and the transformation relationship between
-Timing diagram-In multi-team collaboration, communication is very efficient, and it can also be a detailed structure of code logic
-Class diagram-how to organize the code, the relationship between each class

Text|BeeOML

attention to Dewu Technology, and join hands to move towards the cloud of technology 1609b51978f592 bold


得物技术
874 声望1.5k 粉丝