CSC152 2005F, Class 28: Parameterized Classes II : A Review of Polymorphism Admin * Kudos to Jacob * Sorry that this topic is taking longer than I planned, but I think it's better to go through stuff carefully and make sure you understand it. * Sorry for the confusion at the end of last class; believe it or not, but we did get the results I was expecting, just not in the form I expected. Overview * Generalizing our solution, revisited. Status: * Wrote expt2 * Trying to generalize using interfaces Using Interfaces and Polymorphism * Situation: * You have a method, m, that operates on one class, c, of object * You want to make it operate on similar objects in class d. * Preparatory thinking * Determine which of the original objects's methods you rely on * In expt2, we rely on a constructor and on multiply * Decide whether or not methods with the same name and semantics can be expected in all similar classes (if not, this technique probably won't work) * BigIntegerVariable: check * DecimalVariable: check * StringVariable: Um ... what does it mean to multiply or exponentiate a string? No. * Rabbit: Check * Programming * Devise an interface, i, that lists the methods m depends on. * May need a hack for constructors * Update m to use i in place of c. * Indicate that your original class (c) implements i * Make any changes necessary to ensure that the previous indication is correct * Test * Indicate that your new class (d) also implements i * Make any necessary changes * Test