Re: How C++ NULL pointers can violate LSP

From: Phlip (phlip_cpp_at_yahoo.com)
Date: 07/27/04


Date: 26 Jul 2004 19:42:16 EDT

Wavemaker wrote:

> void funk(SimCity &aCity)
> {
> aCity.throwParade();
> }
>
> There is no need to test for NULL now. Where ever "aCity" is
> created, it's the job of the client to make sure it's passed as a
> reference to funk instead of a raw pointer. funk no longer needs to
> worry about it.
>
> Whether or not a NullSimCity class is needed at this point really
> depends on the needs of the client and whether they need a do
> nothing implementation of SimCity. funk doesn't have to worry about
> that.
>
> So maybe we have another reason for using references in C++ instead
> of raw pointers?

I neglected to mention the switch to references. I always move back to them
when I run out of reasons to point.

But switching to a reference won't _enforce_ a NULL-free interface.
References still might be NULL in C++ - they are just undefined if they are.

I run out of reasons to point as an emergent property of other rules - no
'new', classes should receive references to neighbors and not create them
directly, no NULL, smart pointers, RAII, etc.

-- 
  Phlip
  http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces


Relevant Pages

  • Re: Opinions on the Law Of Demeter
    ... The preferred supplier objects to method M are: ... to do with why Client needs to collaborate with Supplier so Client ... based in embedded identity; passing object references; and employing ... the critter one obtains from the navigation is ...
    (comp.object)
  • Re: Troubles with ActiveX-EXE (Out-Of-Process Server)
    ... If all the client connections are terminated properly, and the server isn't ... continuing to hold references on its own objects, then the ActiveX EXE ... EXE's own Collection is keeping references to those objects, ...
    (microsoft.public.vb.enterprise)
  • Re: idl questions
    ... the client references the dll ... even though there's no direct references to that class in the exe? ... then everything compiles and runs fine ... that creates the tlb in the /bin file... ...
    (microsoft.public.vb.general.discussion)
  • Re: 5 access 2000 users and 1 AccessXP user
    ... Remove any references you don't need from your mdb. ... Once you have that sorted out, create another mde (assuming you removed some ... The remaining problem is for an XP Client ... > I should also mention that, before the XP Client running Office 2000 was ...
    (microsoft.public.access.conversion)
  • Excel Office 2000 error
    ... Have you checked the references on the Client machine? ... Just open the VBA editor on the clients machine, ... client computer for this file. ...
    (microsoft.public.excel.programming)