OO Programming  «Prev  Next»
Lesson 5 Video store example: eliminating classes
Objective Eliminate classes in the problem domain.

Eliminating Classes in the Problem Domain

Once you have assembled your long list of possible class names, you should evaluate the list with an eye toward possibly eliminating some names.
For example, consider this list of nouns related to a project to create an application that will track
  1. video rentals,
  2. video stock on hand, and
  3. video reservations.
The list is long and comprehensive, and includes a number of entities found in the video store business:

Account Late Charge Sale
Address Membership Store
Charges Name Title
Clerk Phone number Video
Credit card # Rental  
Customer Rental charge  
Food Rental length  
Inventory Reservation  

There are a number of reasons for removing a class from your list:
  1. The entity the class represents is outside of your problem scope. For example, for the video store project, the application only tracks videos that are rented.
    The nouns "Sale" and "Food" therefore can be removed.
  2. The noun does not appear to have any behavior associated with it, or to pull together a number of related pieces of information. A video, for example, will have all kinds of values associated with it (title, rental charge, and so on) and can be marked as rented and marked as reserved, among other things. But a late charge is just a single number, it's not complicated enough to make a good class. The same is probably true of customer values like Phone Number and Address.
There are nouns on the list that are synonyms. Looking at the nouns on the video store list, you might ask what's the difference between Account and Membership? And are there Customers who don't have an account or who are not a member? These three classes have no separate existence, and it's best to pick one word and jettison the other two.
Here's the stripped-down list of class names for the video store:
  1. Customer
  2. Inventory
  3. Rental
  4. Reservation
  5. Title
  6. Video

Eliminating Classes - Exercises

Click the Exercise link below to choose the classes in your Checkbook Manager program.
Eliminating Classes - Exercises