December 2009
Intermediate to advanced
380 pages
9h 2m
English
| Pattern 23 | Enforcing Polymorphic Type Safety |
This pattern detects type incompatibilities in object pointer assignments in object-oriented languages like C++.
Beyond the type checking done in Pattern 22, Enforcing Static Type Safety, object-oriented languages have one more type hazard to worry about: polymorphic object pointer assignment. Polymorphism means that a pointer can refer to objects of multiple types. In contrast, C pointer assignments have to be between exact types. The key difference then between this pattern and the previous lies in the definition of type compatibility. Let’s take a look at a C++ example that demonstrates what we need to handle:
| | Cat *pCat; |
| | Bengal *pBengal; // assume Bengal subclasses Cat |
| |