OO homework second summary

 

Design strategy and its changes from three assignments

  The focus of these three operations is on multithreading, taxis, IFTTT, elevators, and understanding the use of multithreading in different aspects. The main ones are synchronization and asynchrony, information interaction and sharing between threads, lock and time relationship. In addition, there is still important class encapsulation, which is also the main content of object-oriented. Still focus on the program architecture design itself, think about the implementation of multi-threading, and think about and execute design strategies. Then there is the test interface. I learned to provide test interfaces, use test interfaces, and write test functions on other people's test interfaces.

job analysis

  The overall design idea of ​​the sixth operation IFTTT:

  1. In order to reduce the cost of reading file attributes on a large scale, the program dynamically maintains a directory Map, which saves the relevant information of the file at the previous point in time. For each listener thread, each judgment only needs to pull the relevant data from the Map. For the relationship between the listener and the Map, the observer mode was initially considered for implementation, but this mode has insufficient feedback support for the thread's own information, so the thread is selected to pull the information as needed.
  2. The IF ** THEN ** operation uses a dynamic array selection function. At first, I read the guide and thought that multiple detection functions could be bound to a file as a thread, so all operations were defined for each monitoring thread, and the Bind related operations in the dynamic list. Later, it was found that each trigger corresponds to a thread, so consider using the decoration mode for dynamic binding of triggers and tasks.
  3. Implementation of safe read and write classes. The problem with the File class is that it is non-blocking IO, so it needs to be changed to blocking IO, and then thread synchronization can be performed.

 

  The design idea of ​​the seventh operation taxi dispatch:

  1. System brief

  This system is a taxi dispatching system, which mainly manages and dispatches the initialized 100 taxis according to certain specifications. From the perspective of the user, it is necessary to conduct a comprehensive ranking according to the credibility, the distance from the user's location and other information 3 seconds after the user sends a car request, and select the optimal vehicle to transport the user to the designated location. For each taxi, you need to ensure that you are in motion at all times, have the opportunity to participate in more request responses, and improve your credibility. At the same time, relevant information needs to be recorded for each valid response request. The main problem of the system is the conflict between the delay of taxi transaction processing and the time window of its own movement change. For example, for each taxi, the time it takes to walk an edge is 200ms, then the transaction processing of the taxi itself (such as state transition, routing, etc.) must be less than 200ms. The update of the GUI interface should be relatively gentle, and the operation of jumpers should not occur.

  2. Interaction Analysis

There should be three classes of objects that interact with the system: taxis, request queues, and related information record classes. For taxis, it should at least have a unique identification number, three attributes: current location, current status, and credit. For the request queue class, at least one request should contain all the information, namely: request location, request time, destination location. For the output class, it is necessary to specify the output target file. The taxi management system schedules the taxi itself, is responsible for updating the taxi information and completing the related scheduling tasks, mainly including the following aspects: 1. Every 200ms, update the location information of the taxi; 2. According to the current state of the taxi, Update taxi status information; 3. For taxis that meet certain conditions, assign pick-up tasks. The taxi management system responds to the relevant requests in the request queue class, and selects taxis that meet the conditions after a time window ends and feeds back their information to the management system. The output class is mainly used to record some operations triggered by the management system, such as the qualified taxi information after the user sends a request, the information of the taxi after the end of the last time window, and the finally selected taxi number according to the conditions. The actual implementation adds more classes for separation of responsibilities and loose coupling.

  3. Concurrency analysis

The concurrent behavior in the system mainly includes the following aspects:

  1) The update of the status of the car rental, the update of the status and location of each taxi needs to be completed in a short time at the same time, and a large delay is not allowed.

  2) The location of the taxi itself is parallel to the car selection process after the request is completed.

  3) Output relevant information about the request to the output class.

Considering these three aspects, the following factors need to be considered when designing for concurrency:

  1) The update and acquisition of taxi locations need to be synchronized to prevent changes in information during acquisition.

  2) The delay of taxi status update is as small as possible to prevent the update of other taxis from blocking.

  3) The change of the taxi state can only be changed by a blocking method, which prevents the operation error of the taxi caused by multiple state changes.

  4) When recording relevant information, the normal operation of the taxi should not be blocked due to specific operations. 

 

 

 Bug analysis and experience

  During this period of work, one of the main contents is to provide test threads for testers and to use test threads to test bugs. This reiterates the concept of object-oriented code encapsulation, with an interface to test the overall program. In addition, the main places where bugs are raised are the details caused by time constraints, and there is no error in the overall thinking. Therefore, during this period of work, the importance of thinking about program ideas in advance, multi-threaded construction, thinking clearly before starting, and focusing on improving the program structure is reflected.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325165239&siteId=291194637