Integrated example of easy getting started with Unified Modeling Language (UML)

Source: Internet
Author: User
Ten years ago in China, ATM was a very new thing, which is now everywhere in the streets and alleys of the city. We often deal with ATM in our daily lives. In this chapter, we will use the simplified ATM system as an example to apply the knowledge of the use case diagram, class diagram, sequence diagram, state diagram, activity diagram, and collaboration diagram learned in the previous chapters to this example.

5.1 use case diagram   

Participant "bank depositor" and ATM. The simplified ATM only supports withdrawals, deposits, and deposits. Other functions are not described in detail.


Figure 5.1 automated teller machine (ATM) system use case diagram

Bank depositors make withdrawals, deposits, and other services at ATMs.

 5.2 class diagram   

The banking system diagram shown in Figure 5.2 is similar to that shown in Figure 3.5, except that staff are switched to ATM. The entire banking system includes the account library, the bank depositor library, and the ATM system.

Many individual accounts constitute the account library. An account has three attributes: Account type, account number, and balance. They are all private, and their types are char, Int, and double. The six operations are settype, GetType, getaccountnumbe, setaccountnumbe, caculatebalance, and getbalance, except that caculatebalance is protected.

Settype: Set the Account type. The return type is void, the parameter type is Char, and the input Account type.

GetType: Account type. The return type is Char and no parameter is set.

Setaccountnumbe sets the account number. The return type is void, the parameter type is int, and the input account number.

Getaccountnumbe: gets the account number. The return type is int and no parameter is set.

Caculatebalance calculates the balance. The return type is void and the parameter is double. The first parameter is the input deposit amount, and the second parameter is the deposit balance, which is both input and output.

Getbalance obtains the account balance. The return type is double and no parameter is set.

Many bank depositors make up a depositor database. The ATM system includes many ATM machines. What are the attributes and operations of bank depositors and ATM machines? their visibility and return types, number of parameters, and parameter types are clearly displayed in the class diagram. More attributes and operations can be added to make the class diagram more detailed and complete, so that every member of the project can understand the structure of the entire design class without ambiguity. This class chart is too simple for a real banking system. For example, you can define an abstract class that contains the most basic attributes and operations of an account. Some operations are first defined as abstract, such as the calculation of balance. Then inherit this abstract class. We can have saving accounts and checking accounts. Different accounts have different balance calculation methods. We can add specific algorithms. There may be some special operations for different accounts. We can also add them. For example, the saving account can enjoy a discount on the air ticket when the deposit reaches. By using a class chart, designers can not only clearly express their own design intent, but also help them organize their own ideas and enrich and optimize their own designs.


Figure 5.2 banking system diagram

  5.3 Sequence Chart   

Figure 5.3 describes the flow of information when a customer withdraws money from an ATM. In chronological order. Because it is only an example, there is no fault in the whole process, and only the withdrawal is completed. The figure shows how messages interact with different objects in the system.

Through the flowchart, we can clearly see how the system works, how information and control between various parts of the system are sent, and whether the entire process is reasonable. The flowchart is very helpful for our design. Note that no lifeline terminal in this figure has an "X", because there is no object lifecycle in this process. When an object ends, you need to draw "X" on the corresponding lifeline terminal, indicating that the object is destroyed at this time.

First, the bank depositor inserts the ATM card into the host machine, and the host machine sends the information to the customer management. The customer management puts forward the query password, and the display part displays the request for entering the password ..... Because this sequence chart is long and clear, it is easy for beginners to understand and I will not explain it too much here.


Figure 5.3 ATM withdrawal sequence

  5.4 status chart

Figure 5.4 describes several states that a customer can perform operations on an ATM and the conditions for switching between States. Because it is a simplified example, in addition to waiting for the initial status of the customer to insert the magnetic card and the termination status of the end service, the customer will be in four states: enter the password, select the service type, deposit and withdrawal.

Figure 5.4 ATM status chart

After the magnetic card is inserted, the password is entered. When the password is entered correctly, the selected service type is entered. If the entered password is incorrect, the service ends. After selecting the service type, the customer can enter the deposit and withdrawal status. After the storage and withdrawal ends, the customer can either end the service to the final state, or choose to continue the service to return to the selected service type state.

Through the status chart, we can learn without ambiguity how different active roles are converted under different conditions, what are the conversion conditions, whether deadlock occurs, and whether conditions are not fully considered, whether the status cannot be reached. The status chart helps us identify problems and correct them in time.

  5.5 activity diagram  

Figure 5.5 References Randy Miller's a hands-on introduction for developers. The customer management and transaction management in Figure 5.3 correspond to the bank in Figure 5.5, the hosts, display, and input devices and money counters in Figure 5.3 correspond to the ATM machina in Figure 5.5, and the bank depositor is the customer. At first glance, the activity diagram and sequence diagram are very similar in meaning. However, we can note that the sequence diagram focuses on the order of time, while the activity diagram focuses on the mutual constraints between parts, which can be effectively expressed for some parallel activities. For example, in the fork and join operations in Figure 5.5, we can clearly see the existence of some parallel activities.

This activity chart starts with the customer card insertion and ends with the customer card fetch. We can see that although the focus of the activity diagram is not in the chronological order, we can also get the time information.
  

Figure 5.5 ATM banking system activity diagram

  5.6 collaboration Diagram  

In chapter 4, we know that a collaboration diagram and a sequence diagram can be converted without information loss, but their focus is different. The sequence diagram focuses on the time sequence of message passing between objects, and the Collaboration diagram focuses on expressing static connections between objects. Figure 5.6 converts figure 5.3 to a collaboration chart.

1. Insert an ATM card
2. Accept ATM cards
3. query the password
4. Display Password Input requests
5. Enter the password
6. Pass the password
7. Request to confirm the validity of the password
8. confirm the validity of the password
9. Ask about the service category
10. display the request for the input service category
11. Enter a withdrawal request
12. withdrawal request
13. Ask about the withdrawal amount
14. Request for displaying the input amount
15. Enter the withdrawal amount
16. Transfer withdrawal amount
17. Confirm the withdrawal amount
18. Show request for confirmation amount
19. Enter confirmation
20. Transfer Confirmation Information
21. Amount validity confirmation request
22. Confirm the amount and legal nature
23. banknote issuance request
24. Calculate account balance
25. banknote issuance
26. banknote Retrieval
27. Transfer the balance and ask if other services are needed
28. Show account balance and prompt to select the following service
  
Figure 5.6 ATM system collaboration Diagram

From the figure, we can see that the roles of the Collaboration diagram and the objects of the sequence diagram correspond one by one, while the cooperation relations of the objects on the collaboration diagram and the message transmission on the sequence diagram correspond one by one.

 

 


This article from: http://www.sawin.cn/doc/SoftMethod/UML/TheEdge4.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.