Re: I/O class: how to design for special case



Simon,

Firstly, your description of the problem and suggested solutions is
nice. Thankyou for taking the time to explain the problem well and
come up with some possible solutions. Typically I see one liners with
very little to go on.

Secondly, Can CFoo provide a factory method that provides a CFooBuffer
with the CFoo methods able to accept this buffer.
Eg: CFooBuffer CFoo::newBufferWithDefaultSize()

This way your asking the object with the information to do the work for
you.

To avoid the buffer copy you could also have the CFoo::out methods take
a CFooBuffer but then as the CFooBuffer to write its
contents to where you need it to go. Here is an example if the output
was to go onto a socket ....

bool CFoo::out(cfooBufferInstance) { cfooBufferInstance.storeOn(socket)
}

ie: we still asking the object with the information to do the work. It
inverts control and is the OO approach IMHO.

I hope this helps,

Keep well

Rgs, James.
(http://www.jamesladdcode.com)

.



Relevant Pages

  • Re: I/O class: how to design for special case
    ... that CFooBuffer does its own reading. ... "Object" would have to be replaced by a real class or ... this uses a different API and handle data type: ... buffer is a useful approach: we can imagine cases where the buffer has ...
    (comp.object)
  • Re: I/O class: how to design for special case
    ... This design is something that I've given some thought to, ... Can CFoo provide a factory method that provides a CFooBuffer ... > with the CFoo methods able to accept this buffer. ...
    (comp.object)