Boost logo

Boost :

From: Dave Harris (brangdon_at_[hidden])
Date: 2004-10-09 07:46:55


In-Reply-To: <ck6la2$kki$1_at_[hidden]>
nesotto_at_[hidden] (Thorsten Ottosen) wrote (abridged):
> Conclusion: disallowing 0 will not only lead to simpler, safer
> programs, but it will probably also boost performance.

The null object pattern can only be used if all the object's member
functions have trivial post-conditions. If instead I have code like:

     dog.walk_to( pTree );
     assert( dog.location() == pTree );
     // ... more code assuming the dog's location.

then it is not going to work with a null_dog. If people use it anyway
there will be tears before bedtime.

Of course, this is no more an argument against ptr_vector<Dog> than it is
against std::vector<Dog>. I think the problem here is the name.
"ptr_vector" sounds so much like a vector of pointers that people expect
null pointers to be supported. There is a gap between what those people
want and what ptr_vector supplies. The null object pattern is not a
solution here. It just papers over the crack.

-- Dave Harris, Nottingham, UK


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk