So I got this interface to a memory buffer of sorts. I'd like to provide TStream access to this buffer so it can be read from and written to using System.Classes.TStream, for interop with existing code.

So I got this interface to a memory buffer of sorts. I'd like to provide TStream access to this buffer so it can be read from and written to using System.Classes.TStream, for interop with existing code.

I'm struggling to decide the best approach to this trivial problem, and would welcome some thoughts from a "user perspective".

It's highly unlikely I'll even provide more than one implementation of the interface, so my two primary options are:

- Provide a property Stream: TStream in the interface, and have the buffer implementation return some private implementation of TStream, not unlike how GetEnumerator is done for the generic collections. Lifetime would be that of the buffer instance, so the user has to ensure the buffer is alive for the duration of any TStream operations.

- A separate "glue class", a TStream descendant where I pass the buffer in the constructor. This places the burden of lifetime management of the glue instance on the user.

In either case the the buffer interface is sufficient for the allowed TStream operations to be the same.

Thoughts?

Comments