CSC223, Class 28: Discussion of In-Class Exam 1 Admin: * Late: Luis, Kat * Missing: Ryan, Chase * Whee! We have prospective applicants (or we should). * Warning! I will have limited email access this weekend. * Exam due Monday. * Read more of _Design Patterns_ :-) * HAPPY BELATED BIRTHDAY RYAN! Overview: * Discussion of In-Class 1 * General * Problem 1: UML * Problem 2: Introspection * Problem 4: Testing * Questions on Take-Home 1 * Problem 1: UML and Java Collections Framework * Problem 2: Introspective Testing * Problem 3: Building Factories * Problem 4: Anonymous Inner Classes * Leftover stuff from Wednesday General Issues on In-Class Exam * YOU NEED TO READ INSTRUCTIONS! * Name on every page * Sign AND DATE the honesty statement * How will I balance the two grades? * 2/3 better * 1/3 worse * Can I challenge grades? * Certainly, but I have been known to find new errors * I HATE "You took off X for me and Y for him/her!" Problem One: UML Problem Two: Introspection * Expected * Good definition * Enough code that someone else could write their own * Got * Strange definitions * Introspection is "run time type determination" * Introspection involves building new methods * Little code * Good definition: Like the literal meaning: Look inside itself * Idea that you can determine aspects of a class *and use those aspects* at run time * How? (1) Get the class of the object Class c = *object*.getClass(); Class c = Class.forName(String *name*); Class c = Integer.TYPE; // Boolean.TYPE, Float.TYPE, ... (2) Find a method associated with that class Method[] methods = getMethods(); Method[] mymethods = getDeclaredMethods(); Method m = getMethod(String name, Class[] paramtypes) I want the compareTo(Vec2D) method Method comp = c.getMethod("compareTo", Constructor[] conses = getConstructors(); Constructor[] conses = getDeclaredConstructors(); Constructor cons = getCOnsturctor(Class[] paramtypes) new Class[] { Class.forName("rebelsky.exam1.Vec2D") }); Class.forName("java.lang.String") (3) Call that method m.invoke(Object base, Object[] params) cons. What if I want to call methods that start only with "test" Method[] mymethods = c.getDeclaredMethods(); for (int i = 0; i < mymethods.length; i++) { Method m = mymethods[i]; if (m.getName().subString(0,4).equals("test")) { ... } Problem Three: Good! * Some of you "pushed the envelope" in the comparisons (4) Testing! * NO SIMPLISTIC TESTS! * Expected: * A series of different tests * Different size arrays * Already ordered * Completely reverse ordered * Randomly generated * Duplicate elements * Real verification of postconditions * The result must be in order * The result must be a permutation Questions on the Take-Home Exam? * Problem 1: UML and Java Collections Framework * One diagram suffices * Problem 2: Introspective Testing * * Problem 3: Refactoring * Do we have to provide *all* the code? * It would be nice. * I will survive with partial code that reveals the key ideas. * Do we have to provide definitions? * No, but it might be nice. * Problem 4: Building Factories