The methods of the base classes
The base classes should be able to create an object representing a record of the database-table, retrieve an uniquely identifiable record from the database-table, modify the attributes / fields, write the object back to the database-table, and of course delete the record from the database-table.
So there are already quite a few simple methods to write.
- The constructor - creates an object and retrieves the data from the database-table, if an unique identifier has been provided, otherwise it creates an "empty" object and fills the attributes with default values where provided.
- save method - writes the data back to the database-table. If this is a new object (originally) it adds a new record to the database-table and if no unique identifier has been set so far it tries to create one by itself (sometimes it will be created by the database automatically, then the method should get it and set the attribute of the object accordingly).
- save attribute(s) method - writes only the given attribute(s) to its/their corresponding fields. Only available if object is already in the database-table.
- remove method - deletes the record from the database table. Only if there is a record representing this object, that means a newly created object which has not been saved to the database table, cannot be removed from it.
- set attribute - sets the value of an attribute. The method should check that the data will be valid in the database and reject any invalid value, it should not check that that value is unique to the table if the field in the table is defined unique, but only if for example the string is not longer than the field, or that the numeric value is in the given range either explicitly defined in the database or implicitly defined by the datatype i.e. unsigned smallint cannot be negative or greater than 65768. And of course with date-fields it should check if the given value is a valid data within a maybe given range.
- get attribute - simply returns the value of the requested attribute.