Beihang 2020OO Unit 2 Blog Assignment

First homework

1. Design strategy

This operation needs to realize the operation of a simple elevator. Naturally, I chose to run the three parts of this operation, read in data, schedule data, and elevator operation as three threads. The thread for reading data is relatively simple, and it can be read in sequence according to the provided interface usage method. Scheduling data I implemented a scheduler class, which is used to manage two queues, one is a queue for reading data, and one is a queue for assigning tasks to elevators. As a class, elevators realize the functions of running, entering and exiting people.

2. Scalability

I think the scalability of this job is relatively good. To add an elevator, you only need to create another thread. To add functions, you only need to add it inside the elevator.

3. Program structure analysis

The UML class diagram is as follows:

The collaboration diagram is as follows:

The metric analysis is as follows:

Except for the run method of the elevator, the complexity of other methods is better controlled, because the elevator needs to consider which floor of the priority to pick up, so the complexity of the run method is relatively high. It can also be seen from the class diagram that the complexity of the elevator class is the highest.

4.bug analysis

In this assignment, I found no bugs in the strong test and the mutual test. In the mutual test, I didn't find other students' bugs.

Second job

1. Design strategy

This operation required the realization of multiple elevators and expanded the reachable floors. I added a whole queue on the basis of the first job to provide each elevator with its own exclusive queue. Due to the appearance of negative floors, a new method of indexing based on floor conversion queues has been added.

2. Scalability

The scalability is better, and the new functions only need to add methods or classes in the corresponding class.

3. Program structure analysis

The UML class diagram is as follows:

The collaboration diagram is as follows:

The metric analysis is as follows:

It can be seen that the analysis of the second operation as a whole is not much different from the first operation, and the run method of the elevator is still relatively complicated due to design reasons.

4.bug analysis

In this assignment, I found no bugs in the strong test and the mutual test. In the mutual test, I didn't find other students' bugs.

Third homework

1. Design strategy

This operation adds the type of elevator and the function of transfer and dynamic increase of elevator. For the type of elevator, I define a floor array for the elevator to mark which floors can be reached, and use String to save the type and name of the elevator. For transfers, I used the method of writing back to the request queue. First, when the scheduler finds a request that cannot be reached directly during scheduling, it will mark this object with a special one. When the elevator receives a specially marked Person, it will send it to the nearest transfer floor (1st or 15th floor) and write the request back to the request queue. For dynamically adding elevators, you only need to create elevators in the reading thread.

2. Scalability

I think the scalability is quite good for this job. Due to the separation of elevator, dispatcher and reader, a relatively good scalability is achieved.

3. Program structure analysis

The UML class diagram is as follows:

The collaboration diagram is as follows:

The metric analysis is as follows:

The complexity of this assignment is slightly higher than the previous assignment, but overall it is fairly normal.

4.bug analysis

In this assignment, I found no bugs in the strong test and the mutual test. In the mutual test, I found that some students would time out when transporting a large number of transfer personnel, and some students could not reach some special needs.

Experience and experience

In the study of the second unit, I deeply realized the importance of thread safety. Almost 80% of the mistakes of my classmates were caused by deadlock or data risk caused by thread insecurity, and the problem of thread safety is very It may be difficult to find out when testing by yourself, some errors may occur with a very small probability. There are also design principles that must be clear. Whoever should do the work should do it, and a thread should not be allowed to do work that does not belong to it. This not only improves the degree of coupling, but may also cause unexpected errors. We should plan the general framework of the entire program from the beginning, and we can't write where to count.

Guess you like

Origin www.cnblogs.com/C9H13O3N/p/12706991.html