Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It looks like your desire is that instances of every class are allowed to communicate pub/sub with the class they derive from, plus all of their siblings (classes that derive from their parent class).</p> <p>This is a very particular requirement, and particular requirements usually demand interesting solutions.</p> <p>One solution would be to create a pub/sub class for every parent class. Each class associates itself with its parent's class and its own (so that it can communicate with its siblings and all of its decedents respectively).</p> <pre><code>template &lt;typename T&gt; struct PubSubSingleston { static PubSubManager instance; } template &lt;typename T&gt; PubSubManager PubSubSingleton&lt;T&gt;::instance; </code></pre> <p>A class can then associate itself with those pub-sub "layers". Cleanest way to do that is probably with multiple inheritence, if you support it</p> <pre><code>template &lt;typename ClassT, typename ParentT&gt; class PubSubHelper { public: PubSubHelper() { PubSubSingleton&lt;ClassT&gt;::instance.associate(this); PubSubSingleton&lt;ParrentT&gt;::instance.associate(this); } void publish(const Message&amp; inMessage) { PubSubSingleton&lt;ClassT&gt;::instance.publish(inMessage); } }; class X : public B , PubSubHelper&lt;X, B&gt; { ... } </code></pre> <p>There are many other patterns (like CRTP) that work with this, but the fundamental technique is associating a class with some PubSub object associated with itself, and another associated with it's parent.</p>
 

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