Checklist for (C++) class authors
I’ve been reading, “Ruminations on C++”, an interesting C++ book by Andrew Koenig and Barbara Moo. It tries to explain the “why” of C+ programming instead of just the “how”. It also gets you to think more about your programming.
I found this list of questions for designing classes useful.
- Does your class need a constructor?
- Are your data members private?
- Does your class have a constructor without arguments?
- Does every constructor initialize every data member?
- Does the class need a destructor?
- Does the class need a virtual destructor?
- Does your class need a copy constructor?
- Does your class need an assignment operator?
- Does your assignment operator handle correctly assignment of an object to itself?
- Does your class need to define the relational operators?
- Did you remember to say delete[] when deleting an array?
- Did you remember to say const in the argument types of your copy constructor and assignment operator?
- When a function has reference parameters, should they be const references?
- Did you remember to declare your member function const appropriately?
Leave a Comment