A Class Design Checklist: Discussion

Steven J. Zeil

Old Dominion University, Dept. of Computer Science

Table of Contents

1. The Checklist
2. Discussion and Explanation
2.1. Is the interface complete?
2.2. Are there redundant functions or functions that can be generalized?
2.3. Have you used names that are meaningful in the application area?
2.4. Preconditions and Assertions
2.5. Are the data members private?
2.6. Does every constructor initialize every data member?
2.7. Describe the default constructor…
2.8. Describe the big 3
2.9. Does your assignment operator handle self-assignment?
2.10. Does your class provide == and < operators?
2.11. Does your class provide an output routine?
2.12. Is your class const-correct?

The basics of using C++ classes to program ADTs should be familiar to you.

But experienced C++ programmers know that there are a number of steps in going from a very basic ADT class to one that is robust enough to employ in real applications. I've tried to codify some of these steps into a C++ Class Designer's Checklist. This is a set of rules that I believe you should apply every time you find yourself designing or modifying the design of a class.

In this lesson, I'll present the checklist, then show how to use it in refining some simple ADTs.

Many of the rules here call for you to think beyond the immediate needs of the application you are writing today. Instead, these rules seek to improve the chances that your ADT is robust and flexible enough to survive changes and rewriting of this application and is also ready to use in other future applications that feature the same abstraction.

In the Forum:

(no threads at this time)