CSC223 2004F, Class 32: Choosing and Using Heuristics Admin: * Scumbags stole projector in 2435 and cable from here * Ryan is sick; Kat is just missing; Gene's alarm probably didn't work * No alum talk today! * Math/CS lunch today! * Friday's positives * Everybody enthusiastic about presenting * Presenting groups did a good job * Good interfaces * Cats! * Friday's negatives * YOU SHOULD REMEMBER STUFF FROM CLASS TO CLASS! * Subject * General details * YOU SHOULD BE ABLE TO SYNTHESIZE THE STUFF YOU'VE FORGOTTEN (or never learned)! * Assignments for today: * Finish chapters 4 through 7 * Try to decide which heuristics apply to the choice of relationships and ways to obtain usable objects QUIZ: * Subject: "CS223: Sam is upset" * Why did you not bother to figure out what the homework was for today? * Why did you not do the homework for today? * What can I do to give you more incentive to do the work? * Anything related Overview: * How today's class works * Choosing a relationship * Choosing how to get objects to use /Choosing a Relationship Classes and Objects/ * Use * Contain * Directly * Via association * Extend * Associate * Contain * Create * Other (default) /Choosing an Object/ * The ways in which an object obtains other objects to use * Passed as a parameter to a method call * Contain that object * Contain a reference to that object * Create the object ("rich person's solution") * Ask an oracle for the object * Use a global object * Pass the request to an oracle for forwarding HOW DO WE MAKE THE CHOICE OF WHICH WAY SAM GETS A PEN? * First answer: Heuristics * Kat's first heuristic: If the object is used in only one method, you should either (1) receive it as a parameter or (2) create it yourself Notes from Evan Case: Relationship Choices Riel: - 4.14: Objects that share lexical scope should not have *uses* relationships between them. -> used by containing class ex. ATM: card reader should pass error to ATM and let ATM deal with it rather than ask the ATM for the screen and then talk to the screen directly. [Def'n: "Scope" - limitiation on the visibility/accessibility of a variable or object -- two big ways to limit scope: Lexical/Static: look at the words Dynamic: Look at the execution ] - 4.13: A class must know what it contains, but it should never know who contains it. -> Doesn't help us pick which relationship to choose? So, how do we choose a relationship? In 4.14, it should be *any* relationship, not just *uses*... - 7.1: When given a choice in an object-oriented design between a containment relationship and an association relationship, choose the containment relationship. -> "association containment" vs. "pure containment", choose "pure containment" why this is important: - models the real world better. auto 1 ------> 1 manufacturer 7.1, rephrased: if you have a 1-1 relationship between class A and B and are making a choice between containment and association, use containment. 5.1: (as stated by TangSam) Use inheritance when there is a hierarchical relationship. ex. Grinnell^H "Traditional Company" Pres VP VP VP VP Section Heads Team Leaders Peons So this is a hierarchy, but there wouldn't be inheritance. OOPS: 5.1 really is: "Inheritance should only be used to model a specialization hierarchy." MORAL: Be careful about using your own language. /Detour: Stupid Jokes/ "Is 'anal retentative' hyphenated." As the object of a verb, as in "Sam is anal retentive.": no As adjective, as in "Sam is an anal-retentive grader.": yes