Designing classes Sept. 30 Students planning to take the AB exam need to have experience designing classes. In this section we offer you some advice on design and go through an example. When we design a class to represent an object, we have two pieces ot htink about: the state of the object (which will be the instance data) and what the object does or its behaviors (which will be the moethods). When we think about the data of an object, we need to think about what is required to rpepresent the state of the object. When we think abotu what an object does, we should think about how others might want to use the object. Sometimes you will know exactly how the class will be used. Other times, you won't knowall the ways in which the class may be used. In any case, it is always a good idea to try to timagine what the users of the class will need, now or in the future. A class that is designed well can be reused. On the other hand, you don't want to have a class that does everything. As an example, oelt's design a class that represents an alarm clock. We dodn't know exaclty how the alarm clock will be used in a program ;we must design an alarm clock that could be used in lotso f programs that need to represent alarm clocks. We won't get into implementation details but we will come up with a design that includes the alarm clock's state and its public interface. page 272 First we think about the state that is needed to represent the alarm clock. A simple alarm clock has a current time, plus a stored alarm time. A more sophisticated alarm clock could store several alarm times with a radio station setting for each alarm time. There may also be a value that indicates what type of noise to play when the alarm goes off ( a beeping noise or the current aradio station). Our alarm clock will have just one alarm, and the user can choose a beeping noise or a radio station. Figure 5.8 shows the data for our AlarmClock class. We may need to design other classes to represent some of the alarm clock data, such as a Time class to represent a time. Next we need to think about what an AlarmClock object should do. The user can view and set the current time, view and set the alarm time, view and set the radio station, and change between wkaing up to a radio station and waking up to a beeping noise. So we will give our AlarmClock class the methods listed in Figure 5.9 .These methods make up the public interface of the AlarmClock class. We will not worry about how the alarm clock itself works, only about what it does for the user.