Home  >  Article  >  Backend Development  >  How to create an efficient and scalable database table structure and scalable code? (Example attached)

How to create an efficient and scalable database table structure and scalable code? (Example attached)

WBOY
WBOYOriginal
2016-08-25 10:37:241253browse

For example, now I want to make a package function for a certain mall (the function has been implemented by itself
The key is to answer the questions marked in red below, thank you~O(∩_∩)O~

  1. The initial function of the mall is just to buy a certain product. The package functions added later have been changed to the original code, and the changes are very big.
    How should I make judgments in key places in case I need to add additional features later? How to weaken the coupling of the code and add functions later to reduce modifications to the original code?

Reply content:

For example, now I want to make a package function for a certain mall (the function has been implemented by itself
The key is to answer the questions marked in red below, thank you~O(∩_∩)O~

  1. The initial function of the mall is just to buy a certain product. The package functions added later have been changed to the original code, and the changes are very big.
    How should I make judgments in key places in case I need to add additional features later? How to weaken the coupling of the code and add functions later to reduce modifications to the original code?

You may need three tables using mysql for this problem:

  1. Product List

  2. Package list, package description, price, validity period, etc.

  3. The package and product association table basically has two fields, package ID and product ID. Many-to-many relationship, because a package must contain multiple products, and a certain product will also belong to different packages

In specific implementation, two modules can be developed independently for packages and products, which are the functions of adding, deleting, modifying, checking and purchasing of products, and the functions of adding, deleting, modifying, checking and purchasing of packages. The only coupling point between packages and products is the association table. That is, when deleting a product, you need to pay attention to whether it affects the corresponding package. Other functions are basically not coupled

At the same time, your order table can have a type field to indicate whether it is a package order or a single product order

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn