OO Unit 2 Summary-Elevator Dispatch

OO Unit 2 Summary-Elevator Dispatch

to sum up

In these three assignments, my architecture has not changed much. The first two times followed the producer-consumer model, which was designed through input threads, elevator threads, and schedulers. The device is set to thread. The third job has undergone some refactoring. The main refactoring is the change of the elevator thread and the input thread. I did not assign tasks through the scheduler, and connected the elevator with the input through a shared object. The elevator freely competed for people. Distribution. The transfer is completed through the interaction between the elevator and the dispatcher. The algorithm used for piggybacking the elevator is the LOOK algorithm.

First job-elevator with piggyback

UML class diagram:

coupling degree:

This operation mainly uses the producer-consumer model. When a new person uses the elevator, the person is put into the elevator. The first operation finally has a little object-oriented meaning. First, Input only deals with input analysis. Elevator only cares about the elevator's own operation and piggyback algorithm (LOOK), and Control connects Input and Elevator together through a shared object. Person represents the person, and the person controls his own behavior of getting on and off the elevator. However, because this job did not do a better job of abstracting the methods in Elevator, the final code style still needs to be improved.

Second job-multiple elevators

UML diagram:

Coupling:

This time the job follows the design of the previous job, but this time because of the addition of multiple elevators, the Control (scheduler) is set to a thread, and the elevator-scheduler-input is still performed through a shared object and producer consumer mode Coordination, but this time because of the direct average distribution of people, the performance is not very good. The third job improves the scheduling scheme in consideration of performance factors, but overall it can be seen that the previous two job iterations are still more successful.

The third operation-variable elevator, limited reachable floors

UML diagram:

Coupling:

Timing diagram:

This time the operation took into account the performance reasons, and adopted the method of elevator escort, that is, it is not directly assigned to the elevator, the elevator will only adjust the state according to the shared object, so this time some refactoring was performed, only the elevator-input The way of interacting through shared objects, where Control is the class to transfer, so the performance has been greatly improved.
SOLID principle:
S (single function principle): In the third operation, the Elevator class manages the piggybacking of the elevator, runs, enters and accepts requests, the Control class transfers and assigns, and the Shut class control program finishes running. Single function principle.
O (opening and closing principle): This time through three iterations, the better opening and closing principle was not achieved, because the third part of the restructuring led to the expansion and modification of some methods.
L (Lee's substitution principle): This principle seems not to be used this time.
I (Interface Isolation Principle): This principle does not seem to be used this time.
D (Dependency Reversal Principle): The third operation has achieved a better D principle. This is because the Elevator, Control, etc. do not depend on specific examples, so the better D principle is achieved.

BUG analysis:

In these three operations, there were no errors in the public test and the strong test, but in the second operation, because of an incorrect judgment on the elevator floor, an error occurred in the mutual test due to an equal sign. The homework is quite satisfactory.
I am looking for bugs in the program. I mainly use extreme data and automated testing methods (using an automated test built by cpp, python, and java) . The problem of thread safety is mainly deadlock, but this problem is solved by locking It can be solved by further analysis, but one of the most repeated errors in automated testing is the exit thread error. The main reason is that when the transfer is made, the elevator assigned by the person may have exited, resulting in an error. Through the analysis of print, I feel that this method can quickly locate the error. The focus of this unit's testing is on thread safety.
In terms of hacking others, hacking is also done through extreme samples and automated tests constructed by ourselves.

Experience

First of all, through the second unit of learning, I have a deeper understanding of object-oriented, and through three iterations of development, I gradually understand the benefits of object-oriented programming, and I feel that I have greatly improved the writing of automated evaluation In terms of design patterns, through seminars and teacher explanations can also understand one or two. If you choose the right design pattern in object-oriented programming, you can make the code simple and clear and conducive to development. Learning is an object-oriented journey.

Guess you like

Origin www.cnblogs.com/zhy123/p/12702303.html