Re: How C++ NULL pointers can violate LSP
From: Phlip (phlip_cpp_at_yahoo.com)
Date: 07/27/04
- Next message: Thomas Gagne: "Re: Static vs. Dynamic typing (big advantage or not)---WAS: c.programming: OOP and memory management"
- Previous message: Paulo Moura: "Logtalk 2.19.0 is now available for downloading"
- In reply to: Wavemaker: "Re: How C++ NULL pointers can violate LSP"
- Next in thread: David Hilsee: "Re: How C++ NULL pointers can violate LSP"
- Reply: David Hilsee: "Re: How C++ NULL pointers can violate LSP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Thomas Gagne: "Re: Static vs. Dynamic typing (big advantage or not)---WAS: c.programming: OOP and memory management"
- Previous message: Paulo Moura: "Logtalk 2.19.0 is now available for downloading"
- In reply to: Wavemaker: "Re: How C++ NULL pointers can violate LSP"
- Next in thread: David Hilsee: "Re: How C++ NULL pointers can violate LSP"
- Reply: David Hilsee: "Re: How C++ NULL pointers can violate LSP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|