Lecture 14: Command Dispatching

Ambient temperature: 73.2oF

Concepts

  1. Dr. Wong is in a food coma from BBs Cafe, probably because today is his birthday.
  2. Never do ball.get_update_strategy().update();. That is an encapsulation violation! Instead, use ball.update_state(), and inside update_state(), the ball itself may ask its update strategy to update(). Or, the ball may implement its updating in an entirely different manner, but it doesn’t matter because encapsulation is intact.
  3. Your balls should have some method (Observer’s update() method could be a good place, if you’re using Java’s Observer-Observable framework) in which they will execute all of their commands.
  4. Anonymous inner classes are important because they create Closures of their current environment, allowing you to have access to the Graphics object and any other Adapters you might want, without having to pass any of them as parameters to a method or a constructor.
  5. Commands are introduced in-depth, with sample code.

Quotes

  1. “And those fields [captured in a closure] never disappear, unlike your hometowns that get turned into suburban wastelands or plains of townhouses.” – Dr. Wong

Resources

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