Computer Science 15-100 (Sections T & U), Fall 2007
Class Notes: Object-Oriented Design (2 of 2)
Logistics
- Reading: L&L Sections Chapter 6 (today: 6.7 through 6.9)
- Iterator and Iterable Interfaces (from
last lecture)
- Enumerated Types Not Revisited (Skip 6.6)
- Method Decomposition == Top-Down Design
- Method Parameters
- Passed "by value"
- Primitives are copies
- Objects are references
- Variable-Length Parameters
public static int averageWithVarArgs(int... vals) {
int sum = 0;
for (int i=0; i<vals.length; i++)
sum += vals[i];
return sum / vals.length;
}
public static int averageWithEnhancedForLoop(int... vals) {
int sum = 0;
for (int val : vals) sum += val;
return sum / vals.length;
}
public static void main(String[] args) {
System.out.println(averageWithVarArgs(1,2,3,4,5)); //
prints 3
System.out.println(averageWithEnhancedForLoop(1,2,3,4,5));
// prints 3
}
- Method Overloading
- Allowed: Same name, different signature
- Not allowed: same signature, different return type
- eg: Math.abs
- eg: System.out.println
- not an example: toString() <-- handled via inheritance
(coming soon!)
- Testing
- Importance of...
- Code reviews / walkthroughs
- Unit testing, test suite, test cases, boundary case analysis,
black-box vs white-box./glass-box testing, statement coverage, JUnit
Carpe diem!