Class Methods Exercise - Defining MySQL Classes

Require:

1. The object has three attributes: id, host, and port

2. Define the tool create_id, and randomly generate an id for each object during instantiation to ensure that the id is unique

3. Provide two instantiation methods, method 1: the user passes in the host and port Method 2: read the host and port from the configuration file for instantiation

4. Customize the method for the object, save and get_obj_by_id, save can automatically serialize the object into the file, the file path is DB_PATH in the configuration file, the file name is id number, verify whether the object already exists before saving, if it exists, throw an exception , ;get_obj_by_id method is used to deserialize the object from the file

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324796677&siteId=291194637