10.07.2015 Views

Programming Guide - Actian

Programming Guide - Actian

Programming Guide - Actian

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

InheritanceThe Terminate method is defined at the top of the hierarchy becauseterminating employees involves the same operation for all classes.The Hire method inserts appropriate entries in database tables. In addition, theHire method for PermanentEmployee inserts such information asNextReviewDate and InsurancePlan. The Hire method of the Manager classinserts the same information as the PermanentEmployee Hire method, but alsoenters information into the BonusRate column.To cause a method to supersede the functions defined at the superclass level,you use the same name for the method (in this case, Hire), but you redefinethe procedure in the user class script for the appropriate subclasses. Theprocess of a subclass's method superseding the behavior of an identicallynamedmethod defined for a superclass is called polymorphism.How You Can Build an Inheritance TreeThe illustrated example in How Polymorphism Works (see page 125) suggeststhat two of the subclasses (PermanentEmployee and Manager) defineadditional attributes at their own level, requiring the Hire method to behavedifferently for the superclass and its subclasses. The scenario is different if twosubclasses define identical additional attributes.Suppose that you create a class to represent contract employees. If the Hiremethod is the same for both temporary employees and contract employees,you could use the same source code for the Hire method in both theTempEmployee and ContractEmployee classes. However, this is a case wheredefining an intermediate abstract class may be more efficient. The followingdiagram shows how you can create an HourlyEmployee class that contains theHire method for both TempEmployee and ContractEmployee:126 <strong>Programming</strong> <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!