11.1. Identifying the Objects and Fields
Say that we want to write a program to track the grades of students. One way to start identifying the classes that we will need is to underline the nouns in the problem description. If we do this we get grade and student. Which of these should be a class, and which should be a field?
To decide whether a noun needs to be a class or a field, determine whether it has more than one piece of data associated with it. A student should have a name and some grades. A student has more than one piece of data associated with it. So student should be a class. Nouns that have other nouns associated with them are classes.
What about name? Well, a name can be represented by a string and it belongs to a student, so it will be a field of a Student class. What about grade? Well, a grade can be represented by a number and it also belongs to a student, so it too will be a field of a Student class. Simple data that can be represented by numbers or strings are usually fields. To determine which class the field belongs to, ask who owns the data, or who should know the data. A student should know her name and her grades.