Rigorously checking that condition is probably unavoidable. It sounds like this core event is tied to a wheel or perhaps a component that is feeding you information and then you are delegating the processing of that data to other specialized sessions. Inherently, there is nothing wrong with an if/else statement based on that condition even if it is a bit repetitive. The problem with trying to do overly clever based event dispatching is that unless you specifically validate the incoming information, someone maybe able to send you malformed data that causes your program to fire the wrong event. And then if you are going through all the trouble of validating the information you might as well go back to the if/else statement to do the dispatching.

As an aside, if you really have that many events and sessions to which you are dispatching, then perhaps you need to conglomerate a bit more and build a second tier for processing and have your events trickle down to keep things a bit more simple. Of course without an overall picture it is difficult to know if this really is the case with your program or not.

-- Nick

In reply to Re: Cutting repetition in POE coding by nicholasrperez
in thread Cutting repetition in POE coding by BUU

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.