Pilot netizen asked: Many reference books are all built into database classes independently of the document class. Basically, a class is to establish a class in which "increase, delete, change, and poor" is achieved. The code seems to be large, of course, through the classification module, it is possible to call the simple function of the object through the database class during use. (Do not use a complete SQL statement, just use the parameters)
According to OO's thoughts, I also feel that the way the book is reasonable, but it is too much trouble, or the method of passing the SQL statement is more habit.
Dear masters, you generally do it, just talk about the benefits of this treatment. Thank you!
Author A: I also agree with the practice. The database currently involved in our project is relatively simple, so I usually package into a class. The member variable of the class is only one, that is, the database connection M_PConnection. Others are functions. If the database is more complicated, I will derive some subclasses to handle different tables. In this way, I think it is convenient to develop, it can be said to implement three-story mode: the interface, database interface and database development are completely separated, and people who do the interface do not have to care about the database, just call the corresponding interface function. . People who are database interfaces only need to care about the interaction of the package class, and those who do the database only need to do a stored procedure, and the triggers can be. This can be developed in parallel, improve the efficiency of the netizen asked: If the point is clear, if the division is divided into clear, strictly follow the structure of the three-story mode and make it clear that this is certainly good.
But during the actual development process, what I encountered is that the structure of the database should be designed, stored procedures, and triggers should write themselves. The operation of the database is also written by the database. It is the UI layer, the control layer, and the business logic layer are also written by themselves. If you write a class, you feel a lot. A written class feels to add trouble to yourself. This is not known that there is anything special to advocate or benefit! !
Ask the heroes to discuss some, thank you! The author A: You this problem is that general programmers will think. Do so many classes, it seems to be a bit repeatable work. However, what we have to think is the reusability and maintenanceability of the program. Although we have a little burden during development, it will be very convenient in future upgrade maintenance. Otherwise, the future upgrade maintenance will be very difficult. It must be noted. As long as we predefine the interface between the three layers, it is equivalent to splitting the project into three parts, the interface between the parts has been defined, then the remaining only three parts are developed. . If that part is upgraded or modified, it involves just this part. Otherwise, you modify a function, which may have a large impact, causing difficulties in upgrading and maintenance. The advantage of the class is to encapsulate, the internal problems are independent of the outside world, which is its benefit. So when defining the class, my suggestion is not to define a public member variable. All member variables are private or protected, adding a GET / SET interface. Doing so, maybe I will say, is it too much trouble? But if you consider the convenience of future maintenance, this work is worth doing. Why do our projects do not do well, the problem is not the first time, but when the user needs to change, the program has an error occurred, and our procedure lacks flexibility, often leads to many parts of the program to be re-made. Therefore, it is very important to maintain maintainability and reusability.