Toward understanding data structuresWhat can an Object do (to itself)?Objects and valuesObjects, values, classesDavid ParnasParnas on re-inventionDavid Parnas (entry in Wikipedia)What about a 'struct' (plain old data)CPS 1002.1Toward understanding data structuresWhat can be put in a TreeSet?What can be sorted?Where do we find this information?How do we understand the information?What can be put in an ArrayList? Why is this different?What operations exist on an ArrayList?What about an array, or operations done on an ArrayList as opposed to what an ArrayList does to itself?CPS 1002.2What can an Object do (to itself)?http://www.cs.duke.edu/csed/java/jdk1.4/docs/api/index.htmlLook at java.lang.ObjecttoString()Used to print (System.out.println) an object, overriding toString() can result in 'useful' information being printed, also used in String concatenation: String s = x + y;Default is basically a pointer-valueequals()Determines if guts of two objects are the same, must override, e.g., for using a.indexOf(o) in ArrayList aDefault is ==, pointer equalityhashCode()Hashes object (guts) to value for efficient lookupCPS 1002.3Objects and valuesPrimitive variables are boxes think memory location with valueObject variables are labels that are put on boxesString s = new String("genome");String t = new String("genome");if (s == t) {they label the same box}if (s.equals(t)) {contents of boxes the same}stWhat's in the boxes? "genome" is in the boxesCPS 1002.4Objects, values, classesFor primitive types: int, char, double, booleanVariables have names and are themselves boxes (metaphorically)Two int variables assigned 17 are equal with ==For object types: String, Sequence, othersVariables have names and are labels for boxesIf no box assigned, created, then label applied to nullCan assign label to existing box (via another label)Can create new box using newObject types are references or pointers or labels to storageCPS 1002.5David Parnas "For much of my life, I have been a software voyeur, peeking furtively at other people's dirty code. Occasionally, I find a real jewel, a well-structured program written in a consistent style, free of kludges, developed so that each component is simple and organized, and designed so that the product is easy to change. "CPS 1002.6Parnas on re-invention "We must not forget that the wheel is reinvented so often because it is a very good idea; I've learned to worry more about the soundness of ideas that were invented only once. "CPS 1002.7David Parnas (entry in Wikipedia)Module Design: Parnas wrote about the criteria for designing modules, in other words, the criteria for grouping functions together. This was a key predecessor to designing objects, and today's object-oriented design.Social Responsibility: Parnas also took a key stand against the Strategic Defense Initiative (SDI) in the mid 1980s, arguing that it would be impossible to write an application that was free enough from errors to be safely deployed.Professionalism: Parnas became one of the first software engineers to earn a professional engineering license in Canada. He believes that software engineering is a branch of traditional engineering.CPS 1002.8What about a 'struct' (plain old data)We use classes, data/state is private, methods are publicWhy do we have rules? When can they be broken?Why are there both structs and classes in C++?What about helping class, e.g., word and frequency together?We can have one class nested in another, then we don't have to worry so much about encapsulationSee recitation example for creating a Class that can be compared using equality and can be sortedComparable interface must be symmetric with .equalsWhat happens if this isn't the
View Full Document