Skip to content

Stream2py design notes

Thor Whalen edited this page Nov 19, 2021 · 12 revisions

Interface options in making a buffer reader

A few proposals

straight code

source_reader = SourceReader(**s)
stream_buffer = StreamBuffer(source_reader, **b)
buffer_reader = BufferReader(stream_buffer, **r)

fluent interface

buffer_reader = SourceReader(**s).stream_buffer(**b).buffer_reader(**r)

nested aggregator

buffer_reader = Aggreg(
    source_reader=SourceReader(**s),
    stream_buffer=StreamBuffer(**b),
    buffer_reader=BufferReader(**r)
)

flat aggregator

buffer_reader = Aggreg(**s, **b, **r)

Discussion

As a general rule, I'm for breaking things into small objects like the three objects we're talking about here, then combining them to get interfaces that might be more appropriate for some contexts.

This means that the two aggregators above don't preclude the other two proposals. In fact, I would argue that they should be built using the fluent interface or straight code methods.

The nested aggregator nicely separates the three roles and their parameters. The same parameter name (with different values) can be used in more than one role. On the other hand, the flat aggregator allows one to share and align parameters, and only a few of the params are actually required, allows for a sparse simple interface for most cases.

Clone this wiki locally