Lecture Date: Monday, March 16
Today we will finish up recursion with a couple of examples and then start talking about classes.
This will lead to a discussion of object oriented programming. In many languages such as Java we like to represent real world objects in our code. These objects are related to the part of the world we are trying to model. What are the relavant objects, well that depends on the model.
Here is a rule of thumb:
- Nouns become the classes and fields
- Verbs become the methods
The trick is in knowing what should be a class and what should be a field. A field is a class-level variable in a class and provides some information about that class.
For example, if
Student was a class, then
birthday would all be fields of the class.
When deciding if something should be a class or a field, consider that classes contain information about them and fields are the information for classes. So, if something has several facets to it, it’s probably a class. If something is simply a piece of data, it’s probably a field for some other class.
We’ll build a couple example classes as we figure all this out.
Code from class: