CSC223 2004F, Class 30: Design Heuristics, Revised: Relationships Admin: * Late: Omondi, Luis, Evan * Absent: Kat, Gene * Questions on Friday's homework? * Draw one tile in the world at different resolutions * Can we do extra work? Certainly. * How do we show multiple bugs? * It's up to you. * Offset them slightly * Draw a number next to the bug * Use color intensity * ... * Prospies Friday. * Any particular activities? * Demonstrations of your homework * Explain the role of computer science in a liberal arts curriculum? * EVERYONE SHOULD BE HERE! * Sam Martin speaks today at 4:30! * Web Raveler: An Infrastructure for Page Mediation * Women's soccer plays at 1:00! * Homework: Try to finish Riel Overview: * Questions on the reading * Quiz! * Kinds of relationships * Obtaining objects to use * Detour: Class design * Inheritance * Polymorphism * Association /Questions/ * I didn't understand any of it. Please explain. * I've forgotten the organization * Chapter 4: Relationship between classes and objects * Kinds of relationships * Aspects of uses relationship * Detour: Class design (enforcing requirements) * Chapter 5: The Inheritance Relationship (19 heuristics) * Chapter 6: Multiple Inheritance (3 heuristics) * Chapter 7: The Association Relationship (1 heuristic) * Does Java support multiple inheritance? * NO * It does support "multiple implements", though * What is "overrides classes" * Inheritance * What about when we modify JLabel and shove it in our WorldView? * Somewhere between Containment and Association * What would it look like if Java did multiple inheritance? public class Car extends ConsumableThing,WheeledVehicle { // Implicit inheritance of all the ConsumableThing operations, like rapidObselescence() // Implicit inheritance of all the WheeledVehcile operations, like crashIntoWall() } * Why doesn't Java support multiple inheritance? * Harder to implement * Unclear what to do when two superclasses provide a method with the same signature * Usually not needed * Experience shows that most multiple inheritance can be handled by multiple implements or containment/association /Quiz! (Closed book)/ * Title: CSC223, Quiz for Class 30 * Riel suggests that there are many different ways that an object can obtain another object to use. Describe them. * Hint: Gas stations /Relationships/ * Containment: One object serves as a field in another object * Containment Association: A pointer to one object serves as a field in another object * Inheritance: One class (superclass) implicitly provides some fields and methods for another class (subclass) * Uses: Objects in one class send messages to objects in another class * Creation Association: Objects in one class create objects that are members of another class * E.g., an object in class A creates an object in class B and sends it to class C * E.g., an object in class A creates an object in class B and calls methods of that object * Other Association: Any relationship not covered above * Note: The Eboard for Design Heuristics 2 contains a discussion of the relationship between Containment and Containment Association Example of association containment: public class BinarySearchTree { BinaryTreeNode root; Comparator order; } // class BinarySearchTree * The relationship of BinarySearchTree to BinaryTreeNode is "containment by association" * In C++ (and other languages), you contain the actual data and not a pointer * In "association containmenment", the contained object is probably "null" by default. * In "real containment", the contained object is a real object with default values /Key Uses Issues: Where does the user get the usee?/ * Option one: Containment or association containment (User contains a usee) * Observation: Where does it get the field? * Riel treats these as two * Option two: User consults an Oracle to find Usee * Observation: Where does it get the oracle? * Option three: "Global" objects, like System.out * Riel fails to mention such situations * Option four: Inheritance * We do call methods of superclasses, so this may be valid * Riel doesn't mention this, perhaps because to him it's a different thing * Option five: Construction (Build the object you want to use) * "supercalifragilisticexpialidocious".indexOf(i); * Option six: Usee sent to User in a message (parameter to message) * Option seven: Query the world /Detour: Can you make a new method at runtime?/ * Yes, in Scheme * Probably not in Java (Ryan will tell us next time), and complicated if it is /Two Important Design Considerations/ * What relationship is appropriate for *this task*? * When I'm using something, where do/should I get it from?