cs231 Lecture Notes Week 2, Monday 1) review of recursion, cont. mergesort -- leap of faith interpretation comment about interface design: modifiers and functions modifier: void method; just invoke it Deck deck = buildDeck (); shuffleDeck (deck); sortDeck (deck); function: does not change the argument. Returns new thing that (might) replace the old thing Deck deck = buildDeck (); shuffleDeck (deck); deck = mergeSort (deck); printDeck (deck); What happens if you forget the assignment? What happens to the old deck if you clobber it? 2) discussion of hw1 what are classes for? (a) definition of new object (instance variables) (b) collection of related methods Syntax issues pertaining to Homework 1: printDeck example from Section 12.0 Something new!!! Object methods -------------- Observation: lots of methods operate on a single object that is passed on a parameter. The object-oriented view of this is that you are invoking a method "on" an object, or sometimes people say you are passing a message to the object. Either way, there is the notion that one of the parameters is special. OBJECT METHODS are an alternate syntax that makes the special parameter invisible! Object methods we have seen: g.drawOval (...); string.charAt (1); When you invoke them, you invoke them "on" an object. All the methods we have written have been CLASS METHODS. You just invoke them. Possible confusion: Sometimes when you invoke a CLASS METHOD, you specify the name of the class, as in Card.printCard (...); Math.cos (...); How can we tell when we are invoking a CLASS or OBJECT method? Ok, so how do we WRITE object methods? 1) leave out the word static! 2) leave out the magic parameter In that case, how do we refer to the magic parameter? 1) using the keyword this OR 2) implicitly! Examples: printDeck and printCard plenty more examples in Chapter 13!