LECTURE 22 NOVEMBER 2004 ASSIGNMENTS Today 6:00 PM Assignment 4 Wed 11/24 CodeLab #11 Wed 12/1 Assignment 5 Design - *polymorphism* - OO programming feature that allows programmers to send the same message to objects from different classes - each class must define it's own implementation - the method that is actually called at runtime depends on the runtime class - helps write code that is easy to modify and extend - *polymorphic message* - a message whose execution differs depending on the receiving object - defining subclasses of programmer-defined classes - all classes automatically inherit from Object if they do not explicitly extend another class - modeling multiple classes - *unrelated classes* - classes that are not connected in an inheritance relationship - neither one is an ancestor or descendent of the other - also do not share a common ancestor (aside from Object) - if classes are related, ineffective design model - end up duplicating common code - use an inheritance hierarchy - if modeling two related classes, may require three classes when using inheritance - once class to model the common features - two more classes, one each to model the specific features - reserved word protected - public to descendent classes - private to everybody else - reserved word extends - from the idea that a subclass extends, or adds on to, it's superclass - inheritance class diagrams - for protected, use the pound/hash symbol (#) instead of - for private or + for public - do not show inherited data members and methods in subclasses - instead, use an inheritance arrow from the subclass to the superclass - except for - overridden methods (more later), which are included - methods that are defined separately in the subclasses - advantage of inheritance - can put multiple different types in an array - use the common parent class as the array type - polymorphism - allow a single variable to refer to objects from different classes - declare variable with a particular type - can assign to that variable - any object of that type - any object that has that type as an ancestor - cannot assign - superclass - *sibling classes* - classes that share a common ancestor class