Computer Science 15-100 (Sections T & U), Fall 2007
Class Notes:   Object-Oriented Design (2 of 2)


Logistics

  1. Reading:  L&L Sections Chapter 6 (today: 6.7 through 6.9)

  1. Iterator and Iterable Interfaces (from last lecture)
     
  2. Enumerated Types Not Revisited (Skip 6.6)
     
  3. Method Decomposition == Top-Down Design
     
  4. Method Parameters
    1. Passed "by value"
      1. Primitives are copies
      2. Objects are references
         
    2. 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
      }
       
  5. Method Overloading
    1. Allowed:  Same name, different signature
    2. Not allowed:  same signature, different return type
    3. eg:  Math.abs
    4. eg:  System.out.println
    5. not an example:  toString()  <-- handled via inheritance (coming soon!)
       
  6. Testing
    1. Importance of...
    2. Code reviews / walkthroughs
    3. Unit testing, test suite, test cases, boundary case analysis, black-box vs white-box./glass-box testing, statement coverage, JUnit

Carpe diem!