Class design: Design steps

Once I know what class I need, I should ask the following questions:

  1. What long-term information will my objects need to know? These will be the instance variables.

  2. What will my objects know at the time they are created? These will be parameters to a constructor method.

  3. Will any of this information change in the course of the object's lifespan? If not, we have an immutable class, similar to String and Integer in the libraries. This has no direct consequences on how the class is written, but the answer does bear on the next question.

  4. What sorts of things will my objects be asked to do? These will translate to instance methods.

  5. Am I sure this is only one class? After answering the above questions, I may find that the class in doing too much, and it can be sensibly split into two or three different classes.

Example: I am designing a program for managing a library, and I want an object to represent a book.

(next)