Let's say I have an object Employee_Storage
that contains a database connection data member. Should this data member be stored as a pointer or as a reference?
If I store it as a reference, I don't have to do any
NULL
checking. (Just how important is NULL checking anyway?)If I store it as a pointer, it's easier to setup
Employee_Storage
(orMockEmployee_Storage
) for the purposes of testing.
Generally, I've been in the habit of always storing my data members as references. However, this makes my mock objects difficult to set up, because instead of being able to pass in NULL
s (presumably inside a default constructor) I now must pass in true/mock objects.
Is there a good rule of thumb to follow, specifically with an eye towards testability?