One of the greatest problems most programmers—especially myself—have is dealing with invalid objects. One of the most cumbersome tasks during the debugging cycle is dealing with issues like null pointer dereference, invalid pointer dereference, and using objects that have been destroyed or otherwise rendered unusable. The Object Registration pattern and the implementation detailed in this article is meant to help identify this code through well formed runtime exceptions that note when and where the violation took place, thus helping to substantially bulletproof your classes.
For example, consider the following code.
HPISocket* pThisSocket; pThisSocket->User("Eric");
The first line of code declares a pointer to an object, but fails to initialize it. The second line tries to actually use the object, triggering an access violation (core dump in Unix). The code itself is quite innocuous looking, so finding it can be a nightmare. Especially if there is a significant amount of code between the declaration of the pointer and its dereference. The same type of problem occurs when a previously valid object is deleted and later dereferenced, or when these invalid pointers are passed as references to other functions.