Categories
CapstoneWeekly

Object-oriented Project

In the process of continuing to contribute to the project, I found that the readability of the entire repository was greatly reduced, even though our team members left a lot of comments. With the increase of functions, putting all the code into app.py will make subsequent development and maintenance becomes more and more troublesome. We need to refactor the project code to make the project organization more reasonable. Since our project uses Flask as our web framework, more than 90% of our code is python code. The python environment has two very interesting concepts (Package and Module) to help developers better use python for modular programming. Through modular programming, we can split large projects into small subtasks and submodules.

The benefits of modular programming are as follows:

  1. Simplify programming, no need to focus on the entire project;
  2. Good maintainability, easy to troubleshoot.
  3. Good reusability, directly use the written module, no need to rewrite.

Flask has no fixed requirements for the project structure, so I decided to use Packages to organize the program. You may ask, what is a package? Simply put, a package is a collection of multiple modules. When the project is large and there are many modules, we can put the modules in the package for easy management. You can use the import statement to import other Python files (modules) and use the classes, functions, or variables defined in the module to reuse the code segments.

Python module: https://docs.python.org/3/tutorial/modules.html

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *