[Typical case of project actual combat] 05. Benefits of separation of front and back ends (send questionnaire)

1. Background

  The following flow chart is the overall process of sending survey questions to users, putting unnecessary business logic on the front end for processing. This leads to logical confusion and is difficult to maintain. One of the purposes of separating the front and back ends is to put the style of the function on the front end and put the business logic of the function on the back end for processing.
insert image description here

Two, ideas

  Clarify the business logic. UML diagrams can be used to sort out and organize the clarification of the business logic, so that we have an understanding of the macro. A picture is worth a thousand words. Sort out the functional style of the front end and the back-end interface corresponding to the functional style. Put the required calculations and complex processing business logic on the backend, and pass the rendering of the data to the frontend for direct display. There is no need to do some complex calculation logic after receiving the message.

3. Process

1. Main business logic

1. On the chapter push page, querying the three executed chapter particles will call the backend interface to save the rules in redis.
2. When the countdown of chapter particle execution reaches 10, the front-end calls the back-end interface to obtain the incentive configuration of the chapter particle, and returns it to the front-end.
3. When the chapter granule ends, judge whether to configure sending questionnaire. If it is configured, call the backend sending questionnaire interface to send the questionnaire, and then continue the process to execute the next chapter granule. If there is no configuration, continue the process and execute the next chapter.

2. Ideas for solving problems

  1. Put the timer into the backend: In this way, when the backend counts down to ten seconds, the incentive rule is called, and the questionnaire is sent when the timer reaches zero seconds. In this way, the logical judgment of the front end is reduced, and the logic is put into the back end. And reduce the entrance.

   2. Cancel unnecessary loops, remove loops on the flow chart, there is no need to call.
insert image description here

Four. Summary

The style and logical calculation of the same function are disassembled. The benefits of this are:
1. Improve the development efficiency, and the front and back ends can be developed by corresponding personnel.
2. Enhance the maintainability of the code and reduce the coupling of style and logic. Solve the problem and locate it conveniently.
3. Improved reusability and strong adaptability. The same set of back-end program codes can be used for various clients such as web interface, mobile phone, and tablet without modification.
Embodies the idea of ​​object-oriented. High expansion, high reuse, low maintenance cost.

Five, the benefits of object-oriented

  1. Modularity and maintainability: Object-oriented programming breaks down a program into multiple independent objects, each with its own properties and methods. This modular design makes the code more maintainable and extensible, and the behavior of the program can be changed by modifying or replacing a single object without having to modify the entire program.
  2. Encapsulation and information hiding: Object-oriented programming uses encapsulation to combine data and behavior into a self-contained object. The object hides the internal implementation details from the outside, and only provides a limited interface for external access. This information hiding mechanism can protect data integrity and security, and improve code reusability.
  3. Inheritance and code reuse: Object-oriented programming supports the inheritance mechanism. A new class can be created by inheriting an existing class, and the properties and methods of the parent class can be reused. This code reuse mechanism can reduce the workload of repeated code writing and improve code maintainability and scalability.
  4. Polymorphism and flexibility: Object-oriented programming supports polymorphism, that is, the same method can exhibit different behaviors according to different object calls. This flexibility enables the program to dynamically adapt and expand according to the actual situation, improving the flexibility and scalability of the code.
  5. Abstraction and conceptual models: Object-oriented programming uses abstraction to transform real-world concepts and entities into classes and objects in the program. This abstraction process makes the program closer to the conceptual model of the problem domain and improves the readability and comprehensibility of the program.

6. How to realize the separation of front and back ends

To achieve the separation of front and back ends, the following steps are required:

1. Determine the architecture and technology stack for front-end and back-end separation. Commonly used architectures include front-end and back-end separation based on RESTful API, micro-service architecture, etc. The technology stack includes front-end framework, back-end framework, database, etc.
2. The front-end and back-end negotiate the interface specification and data format (such as JSON) for data interaction.
3. The back-end development provides API services based on the specification, and the front-end development implements page display and interaction based on API call data.
4. The front-end and back-end development are separated, Git can be used for version management, and the front-end and back-end can be developed and tested independently.
5. The front and back ends are deployed and released independently, and containerization technology (such as Docker) can be used to unify the deployment environment.

In short, the core of front-end and back-end separation is to separate the development and deployment of front-end and back-end, and realize data interaction through API interface, which greatly improves development efficiency and code maintainability.

Seven, the benefits of front-end separation

  1. Improve development efficiency: The separation of the front and back end enables the front and back end teams to develop independently, which speeds up the development efficiency.

  2. Better maintenance: The separation of the front and back ends separates the front-end UI from the back-end business logic. The back-end no longer needs to consider changes in the front-end UI, but only needs to focus on the implementation and maintenance of the back-end business logic, reducing the complexity of maintenance.

  3. Improve user experience: The separation of front-end and back-end allows the front-end to adopt existing front-end frameworks and technologies, improving the freedom and flexibility of front-end development, thereby improving user experience.

  4. Support cross-platform: The separation of front-end and back-end allows front-end development to adopt multiple technologies, support multiple terminals and platforms, and provide a better user experience.

  5. Improve system stability and security: The separation of the front and back ends allows the front end to be executed on the client side, making the back-end services more independent, thereby improving the stability and security of the system.

Guess you like

Origin blog.csdn.net/weixin_45490023/article/details/132500493