UML class diagram (4)

Source: Internet
Author: User
Instance analysis 1-Logon Module

The function of a C/S-based Real-time chat system logon module is described as follows:

The user enters the account and password through the loginform interface. The system compares the entered account and password with the user information stored in the database (User) table to verify whether the user input is correct, if the input is correct, enter the main interface (mainform). Otherwise, the system prompts "incorrect input ".

Draw an initial class diagram based on the preceding description.

 

Reference solution:

The reference class diagram is as follows:

Considering the system scalability, this instance introduces the abstract data access interface iuserdao, and then injects the specific data access object into the business logic object. You can use the configuration file (such as XML file) to save the specific data access class name in the configuration file, if you need to change the specific data access object, you only need to modify the configuration file, the original program code does not need to be modified.

Class description:

Class Name

Description

Loginform

Logon window, omitting interface components and button event handling methods (Boundary class)

Loginbo

The login business logic class encapsulates the business logic (control class) that implements the login function)

Iuserdao

ABSTRACT Data operation class interface, declare the data operation method for the user table, omit other methods except the query (entity class)

Userdao

The data operation method of the User table is implemented in the specific data operation class, and other methods except the query (entity class) are omitted)

Mainform

Main Window (border class)

Method description:

Method Name

Description

Loginform () method of the loginform class

Loginform constructor, initializing instance members

The Validate () method of the loginform class

The interface class verification method is to call the business logic class loginbo's validate () method to verify user input information.

The Validate () method of the loginbo class

Verify the validity of user input information by calling the finduserbyaccandpwd () method of the Data authorization class.

Setiuserdao () method of loginbo class

Setter method, which injects data access objects into the business logic objects (Note: this is for abstract Data Handler programming)

Finduserbyaccandpwd () method of the iuserdao Interface

Business Method Declaration: queries user information in the database using the user account and password to determine the legality of the user's identity

The finduserbyaccandpwd () method of the userdao class

Business Method implementation: implements the data access method declared in the iuserdao Interface


Consumer instance analysis 2 -- Registration Module

A Java-based C/S software must provide the registration function. The function is described as follows:

The user enters personal information through the registration interface (registerform). After clicking the "register" button, the user clicks the entered information through an object that encapsulates user input data (userdto) the data category passed to the operation database. In order to improve system scalability, different data category classes may be required for different databases. Therefore, a data category interface, such as iuserdao, is provided, each specific data category is an implementation class of a data category interface. For example, oracleuserdao is a data category dedicated to accessing Oracle databases.

Draw a class chart based on the preceding description. To simplify the class diagram, personal information only includes the account and password, and the interface class does not need to involve Interface Details.

 

Reference solution:

In the above function description, we can analyze that the system includes three classes and one interface, these three classes are respectively registered Interface Class registerform, user data transmission class userdto, Oracle user data pipeline class oracleuserdao, interface is abstract user data access interface iuserdao. The relationship between them is as follows:

(1) In registerform, The userdto class must be used to transmit data and the data operation class must be used to operate the database. Therefore, there is an association between registerform and userdto and iuserdao. In registerform, userdto can be directly instantiated, therefore, they can be associated in combination.

(2) because the database type needs to be changed flexibly, The iuserdao subclass cannot be directly instantiated in registerform. You can program the iuserdao interface, then, input a subclass object of an iuserdao interface through injection (you will learn how to implement it in the subsequent sections of this book). Therefore, registerform and iuserdao have an aggregation relationship.

(3) oracleuserdao is a subclass that implements the iuserdao interface. Therefore, there is an implementation relationship between the classes and interfaces.

(4) When the adduser () method for adding user information to the iuserdao interface is declared, the userdto object instantiated in the interface class must be passed in as a parameter, then extract the data encapsulated in the userdto object and insert it to the database. Therefore, the function prototype of the adduser () method can be defined as public Boolean adduser (userdto user). In the iuserdao method, adduser () the object of the userdto type is used as a parameter, so there is a dependency between iuserdao and userdto.

Through the above analysis, the instance reference Class 1 is shown in Figure 1:

Figure 1 Reference class diagram of the registration function

Note:When drawing a class diagram or other UML diagram, you can use comment to add some descriptions to the symbols or elements in the diagram, if you need to describe the functions or implementation process of a method in the class graph in detail, You can use the 2 Representation:

Figure 2 example of class graph Annotation

[Author: Liu Wei http://blog.csdn.net/lovelion]

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.