Lecture 11: Factories & Transforming How We Paint

Ambient temperature: 74.8oF

Concepts

  1. If you use reflection to instantiate a class, you must check that the constructor takes the correct amount of arguments, and that they are of the type your code expects them to be. Dr. Wong discovered that in Java 7, the behavior of Java Reflection’s Class.forName( class_name ).getConstructors() method changed, depending on whether the code runs in a 64-bit or 32-bit JVM. The 64-bit JVM returns the constructors in the order they were defined in the class file, which was the original behavior. The 32-bit JVM returns them in a different order. Dr. Wong did not do a thorough check to determine if there was a pattern to the 32-bit ordering.
  2. Dr. Wong went over code and advice for Homework 3 in detail.
    1. The Lecture 10 page on the course website contains full code for most of the Interfaces used in Dr. Wong’s implementation of Factories in Homework 3. These could be a good starting point and/or reference.
    2. JComboBox<T> – only ever use a generic JComboBox, and never use box.getSelectedItem(); – use box.getItemAt( box.getSeletectedIndex() ); instead. The latter is generically-typed and will help you avoid errors.
    3. When you choose a name for a generic class, choose something descriptive.
    4. You will be choosing generic types for your classes, because you will use generics to make sure that the Model, View, and Controller are all using the same type of adapter. Furthermore, doing so will prevent a Model, View, or Controller from being used with another Model, View, or Controller that uses a different type of adapter. Type-safety is good!
  3. Dr. Wong demonstrated Homework 4: FishWorld.

Quotes

  1. “It’s whatever part of the shark I want it to be.” – Dr. Wong

Resources

  1. Lecture webpage: http://www.clear.rice.edu/comp310/f12/lectures/lec11/