On the application of constructors


I didn’t know where I could use it when I started to learn the constructor. Until I wrote a bookmark application a few days ago, it involved the function of adding bookmarks. This is the general idea,

Click the Add Bookmark button, first insert an empty bookmark data into the database, of course, the ID is self increasing, then refresh the page, load an empty form according to the ID, fill in the data, then update the form and submit the data.

This involves a constructor. I added a full parameter constructor by default. That is to say, the system will not generate a non parameter constructor, but when inserting an empty data into the database, a non parameter constructor is needed.

Take inserting user information as an example. User name and password are required. Nickname, email, address, etc. can be default or assigned to default value. If it is empty, only the constructor of user name and password is required.