CSC223 2004F, Class 34: Design Heuristics, Concluded Admin: * Questions on Monday's homework? * Prospectives! Whee! * New reading: Design Patterns, Chapters 1 and 2. Overview: * Choosing ways to obtain objects * Riel's heuristics * Our heuristics * Debriefing on Riel (if there's time) notes by Sam(M). questions on homework for monday? - yes, we have to integrate everything - user interface can suck for now next: we're gonna read Design Patterns! - for monday, read chapters 1 & 2 quick detour: "design patterns are the coolest things since CRC cards" (SamR, 2004) CRC cards refresher: - put down specifics of class - RPG where everyone gets a character (a class) Today's promise: Take-homes will be returned *eventually* Today's topic: More fun with heuristics! Riel vs. CSC223: choosing objects to use Where do classes get objects to use? - suppose method a.bar() wants to use b.foo(), but doesn't yet have b: - a can construct b in bar() - a can previously construct b (at initialization, e.g.) --> a contains or assoc. with b - a receives b as a parameter - a consults a third party for b - Riel suggests a fundamental problem with this one: - Where's the third party come from? - b is a global variable (e.g., System.out) Are there heuristics that help us decide which way to get b? - Kat's heuristic: if only one method uses b, b should be passed to that method (or that method creates b). [ a moment of silence while we think about relevant heuristics ] - 4.5 --> if a class contains objects, it should use them - 4.6 --> most of the methods should use most of the data most of the time - 4.7 --> don't contain too many things - 7.1 --> choose containment over association - 8.1 --> don't use global data to perform book-keeping - Jesse's conflicting heuristic: if lots of things share something, make it global Observation: You (We) have difficulty identifying heuristics that apply. - is that a problem with "the heuristic method" ? - is that a problem with "these heuristics" ? - Riel doesn't give us many useful heuristics for the stuff we've been asked - is that a problem with "something else" ? - we're newbies - it's not very concrete (we haven't seen much code or many particular examples) What is the benefit of reading Riel? - the heuristics themselves - the problems these heuristics illustrate - the process of analysis in deciding which heuristics apply Question: - How often should I apply Riel? - Riel's answer: You're not experienced. Always apply my stuff. You'll see... - Riel's followup: Experienced programmers always apply heuristics; they just know them well enough that they aren't always conscious of the application - in general, keep 'em in the back o' your mind. and keep 'em handy during design