4. Working with Classes : How You Can Create a User Class : How You Can Use Polymorphism
 
Share this page                  
How You Can Use Polymorphism
Because permanent and temporary employees do not share identical attributes, and because different business rules apply, their hiring processes differ. For this reason, the Hire method, defined in a general way for the Employee superclass, is modified at the subclass level to handle additional attributes defined for each subclass.
Moreover, because OpenROAD allows polymorphism, you can write a method for a subclass that builds on the functions of a method of the same name defined for the superclass. For example, the Employee user class defines a Hire method that contains functions common to all of the subclasses of Employee:
Provides a hire date
Provides a unique employee number
Inserts information about the new employee into the database
Checks for errors
Each of the subclasses of Employee modifies the Hire method to its specific needs:
TempEmployee helps to ensure that a termination date is provided at the time of hire and supplies a termination reason
PermanentEmployee inserts the following information into the database:
NextReviewDate
VacationDays
InsurancePlan
Bonus_temp (null if the new employee is not a manager)
Manager provides a BonusRate
The MethodExec system class defines the SendSuperclass method to facilitate the process of supersedence. The SendSuperclass method invokes the superclass's version of the current method, avoiding the need to repeat the code in the subclass's method.
The SendSuperclass can be invoked only on the CurMethod system variable. The same arguments used to invoke the method on the subclass are passed implicitly to the parent. Arguments passed explicitly to SendSuperclass are ignored and a warning message is generated at runtime.
The SendSuperclass method returns current parameters without requiring a byref keyword. If invoking SendSuperclass causes the parent class to change the value of an attribute, that change is returned automatically to the subclass when control returns to the subclass.
The code position of the statement invoking the SendSuperclass method is significant. If it is important for the parent class's method to manipulate attributes or data before running the subclass-specific operations, the SendSuperclass method must be invoked before the subclass's code. If the operations performed by the parent's method are dependent on the operations specific to the subclass, the SendSuperclass method must be invoked after the operations specified for the subclass's code.
The following sections provide methods that exemplify both of these situations.