Skip to content

Apr 04: Abstract Classes

Learning Objectives

After today's class, you should be able to:

  • Generalize multiple classes that have overlapping code.
  • Explain the requirements of abstract classes and methods.
  • Discuss how polymorphism can be done using interfaces.

Hints [5 min]

  • Reminder: lab solutions are on Canvas Files – compare them with your own
  • VS Code's JUnit bug was fixed yesterday – you can update extensions again
  • HW 7 methods will be tested only with valid files – no need for error checking
  • CSVFileProcessor.java and ProductFileProcessor.java are independent
  • Beware of "The Scanner Bug" – need to read the rest of the line after the int

Testing [5 min]

  • What HW 7 means by "round trip" test – each test method:
    1. Creates test data (Ex: Teethbrush, 2D array)
    2. Calls the write() method
    3. Calls the read() method
    4. Assert that the data returned from read() is the test data
  • How to get 100% coverage of a class with all static methods:
    @Test
    public void coverage() {
        new ProductFileProcessor();  // call the default constructor
    }
    
  • Don't forget to implement and use the assertEquals2D() method

Act12 [40 min]

Your To-Do List