4. Working with Classes : How You Can Create a User Class : Examples of Method: Hire Method : PermanentEmployee Version
 
Share this page                  
PermanentEmployee Version
Unlike the TempEmployee class, which invokes the SendSuperclass method only after providing values for attributes critical only to that subclass, PermanentEmployee invokes the SendSuperclass method first and then does additional work.
The PermanentEmployee subclass requires a successful insertion of new employee information into the emp and jobs tables (performed by the parent's version of the method) before it adds a new row to the permemp table. Therefore, it forces successful completion of the first insertions before performing its own insertion.
The PermanentEmployee version of the Hire method handles the following values for the defined attributes of the PermanentEmployee subclass:
NextReviewDate
VacationDays
InsurancePlan
BonusTemp
The Hire method defined for this subclass inserts values from all of these attributes into the permemp table. When this method is invoked on a permanent employee, rather than on its manager subclass, the value of the bonus_rate column of the permemp table defaults to null (only managers are entitled to a bonus).
If the BonusTemp attribute had not been defined for the PermanentEmployee class, hiring a manager would require two separate database operations, an insertion and an update (both into the permemp table). The insertion would be the same one performed by the PermanentEmployee's Hire method, and the update would be required to store the manager's bonus rate.
To enhance performance by executing a single database operation when hiring managers, the PermanentEmployee class has a private BonusTemp attribute, which is null by default. Because this attribute is private, no value can be supplied by invoking this method on a permanent employee object.
The following code is the entire Hire method for PermanentEmployee:
method Hire() =
declare
    errstat = integer not null;
enddeclare
begin
    errstat = CurMethod.SendSuperclass();
    if errstat = 0 then
        CurObject.NextReviewDate =
            CurObject.HireDate + '3 months';
        insert into permemp (emp_num,
            next_review_date,insurance_plan,
            bonus_rate)
        values (:CurObject.EmpNum,
            :CurObject.NextReviewDate,
            :CurObject.InsurancePlan,
            :CurObject.BonusTemp);
        errstat = CurMethod.DBSession.ErrorNumber;
        if errstat != 0 then
            rollback;
            CurMethod.InfoPopup(messagetext =
            'Database insert failed with error ' +
        varchar(CurMethod.DBSession.ErrorNumber),
            message_type = MT_ERROR);
        endif;
    endif;
    return errstat;
end