CS51 - Fall 2009 - Lecture 13
More discussion of interfaces
Lab 5 - Frogger:
Article by Kirschenbaum on Why humanities students should learn to program.
Object oriented design
Decomposing the world into objects
instance variables and constants represent properties
methods represent behaviors
A few things to think about
how accurately do you want to model reality?
are there instance variables / methods that you need that aren't for modelling reality, but which are necessary to get the code to work?
Design of Frogger
What are the classes? What objects appear in the game?
Cars, trucks, etc
What are the properties of a frog? The behaviors?
location, appearance, whether it's alive
moving, dying, being reincarnated
What are the properties of a vehicle? The behaviors?
Note that frog and cars need to know about each other (note resemblance to Ball and Box classes from last lab)
What are the properties of a lane? The behaviors?
Think about how Lane and Vehicle resemble Tree and FallingLeaf from example in earlier lecture.
Note that this is not complete! Quite common to do initial design of a class and then to realize later than you need to add a little more to it, or to change it somehow, in order to get the overall program to work.