Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you mean <em>design patterns</em> literally (i.e. of the GoF variety) then these would be a few relevant options:</p> <ul> <li>Command: pass a callback to the <code>C</code> items (directly or indirectly through B) so that when they want to talk back to <code>A</code> they can simply invoke this callback -- which can even have parameters</li> <li>Iterator: <code>B</code> exposes a view of its aggregate collection directly to <code>A</code>; communication between <code>A</code> and <code>C</code> is then made directly</li> <li>Mediator: Exposes notifications to which <code>A</code> and <code>C</code> might subscribe to; communication is done by posting events</li> <li>Observer: What you already suggested as the first option</li> </ul> <p>If on the other hand you really mean <em>architectural</em> patterns, then typical options are:</p> <ul> <li>Your first option, <code>A</code> subscribing to <code>C</code> events. At first sight this doesn't look like an all-around good idea unless the event is extremely useful all the time, because it requires <code>n</code> objects to aggregate a pointer back to the callback which in the worst case they could even use just once.</li> <li>Passing references to <code>A</code> is another option, but not a good one if you are going to pollute the public interface of <code>A</code> with methods just so that <code>C</code> can call back to it in very specific scenarios. It can be very effective if <code>A</code> already exposes a suitable interface, but be aware that you might need an adapter class between <code>C</code> calling back to <code>A</code> in order to not tightly couple <code>C</code> to <code>A</code>'s interface.</li> <li>A third option would be <code>A</code> iterating over (a view of) the collection provided by <code>B</code> directly and supplying callbacks to <code>C</code> instances; this has the advantages of being quite loosely coupled and that it will use the least amount of memory, but it might be a bit trickier to code.</li> </ul>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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