CSC153, Class 39: Polymorphism Admin: * About my morning * Homework 5 due * Questions on homework 6? * No reading this weekend * Prospies today! Fun Overview: * Inheritance, reviewed * Polymorphism, reviewed * A small Rational example * Lab: O3.1, O3.2, O3.4, O3.5 * Pronounce the following words: Monticello. Nevada. Buena Vista. Inheritance: You can build classes based on other classes and not have to type the code again. Many benefits: Improved reliability, less code, corrections propagate ... Another benefit: Polymorphism Polymorphism: You can build functions/methods/procedures that act on particular kinds of things, and they'll automatically work on "related" things (members of subclasses and implementors of interfaces) * Benefit: Easy to write functions that use a variety of objects rather than writing one kind of function for each object (code reuse, not lots of code to change when you realize you screwed up) * Potential drawback: You have less control over what your procedure is applied to. (Good preconditions and postconditions help.) * Benefit: Your procedure will work on objects in classes that did not exist when you wrote your procedure. Side note: If you make a method static, you call it with ClassName.methodName(...) If you don't make a method static, you call it with objectName.methodName(...) Example (see Examples directory) Moral: Polymorphism doesn't always work the way you want it to. * Lab: O3.1, O3.2, O3.4, O3.5