Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ design, how to represent different stages of a protocol with objects
    primarykey
    data
    text
    <p>This is not so much of a technical question, but rather a c++ design question.</p> <p>Frequently it seems that I have to design programs which have to manage some a protocol which has some sort of connection, parsing stage and abstract view. Typically I try and design my programs with separation of concerns at the forefront.</p> <p>I keep ending out with "stacks" of objects, a system sits ontop of a parser, which in turns sits ontop of a connection (often there are more layers). These objects then use member function calls to call a layer below it (Tx), and uses callbacks (<code>std::function</code>, usually) to capture information coming from the other directions (Rx).</p> <p>This design seems really subpar, as it add complexity, and each layer has to have a progressively bigger constructor and so on. Also because the connection usually uses something like ASIO, the callbacks are generally on different threads so it's hard to reason about thread saftey.</p> <p>Is there a design patterm, or idiom that represent this structure/functionality better?</p> <h2>EDIT</h2> <p>A simple example</p> <pre><code>class basic_connection { basic_connection(std::string address); void send(std::string); std::function&lt;void(std::string)&gt; on_receive; }; </code></pre> <p>I have a few classes like this, which hold that layer's state, and are glue together by their public member functions and callbacks.</p> <p>The layer above this, receives command data processes for the network and calls <code>basic_connection::send</code>. And takes the raw data from <code>basic_connection</code> and converts into commands for the layer above it unprocessed.</p> <h2>EDIT2:</h2> <p>Another issue that I forgot to mention is that you end up forwarding some of the interface though the stack, for example, a top layer still needs to know the connection status.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload