Re: I/O class: how to design for special case
- From: "Simon Elliott" <Simon at ctsn.co.uk>
- Date: 27 Jan 2006 09:55:52 GMT
On 27/01/2006, jladd@xxxxxxxxxxxxxx wrote:
> If you ask the CFooBuffer instance to get the data itself, then pass
> it to the CFoo::out routine.
> The data must be coming from somewhere, so try this:
>
> CFooBuffer::readFrom(Object source)
>
> If the Object is a socket then handle it, if its a file, then handle
> that.
Yes, I can sort of see where you're coming from, and it does make sense
that CFooBuffer does its own reading. But:
readFrom(Object source)
In the real code, "Object" would have to be replaced by a real class or
data type. One alternative approach would be to use
readFrom(int handle)
and assume that CFooBuffer can use read(handle) for whatever handle
type is passed to it. This will work (sort of) for a file, pipe,
socket, serial connection etc. But let's say one day I want to be able
to read adat from one sound card and outout it onto another. Perhaps
this uses a different API and handle data type: int
GetDataFromSoundCard(sound_card_handle_t handle, ...)
Another approach would be to have CFooBuffer::readFrom() as a virtual
function, which gets overridden by a descendent of CFooBuffer. This
allows us to implement the read in any way we want. But the design is
starting to become more complex and harder to use.
But I think your suggestion of a factory method which creates the
buffer is a useful approach: we can imagine cases where the buffer has
to be a DMA buffer, or be contiguous in real RAM, or have special
alignment characteristics. In these cases we couldn't leave it up to
the user of the class to allocate the bufer "by hand".
--
Simon Elliott http://www.ctsn.co.uk
.
- Follow-Ups:
- Re: I/O class: how to design for special case
- From: jladd
- Re: I/O class: how to design for special case
- References:
- I/O class: how to design for special case
- From: Simon Elliott
- Re: I/O class: how to design for special case
- From: H. S. Lahman
- Re: I/O class: how to design for special case
- From: Simon Elliott
- Re: I/O class: how to design for special case
- From: H. S. Lahman
- Re: I/O class: how to design for special case
- From: jladd
- Re: I/O class: how to design for special case
- From: Simon Elliott
- Re: I/O class: how to design for special case
- From: jladd
- I/O class: how to design for special case
- Prev by Date: Re: Technologies and frameworks are killing creativity?
- Next by Date: Re: Top five object/patterns books
- Previous by thread: Re: I/O class: how to design for special case
- Next by thread: Re: I/O class: how to design for special case
- Index(es):
Relevant Pages
|