Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
A dispatch table is a data structure whose values are subroutine references. In C, this would generally be an array of funcp's. In Perl, it's generally a hash (though it can be an array).

An intelligent class, in this context, is more of a group of classes. It's best explained with an example. Let's use the one from above - a bunch of menu items that may be displayed, depending on some set of external conditions.

The immediately obvious solution would be to create some massive if-else structure to handle every obvious possibility. After about 3-4 distinct options, this becomes unmaintainable.

The next solution most people arrive at is to create some massive data structure and some control function that will "walk the tree", so to speak. This is more manageable, but starts to become problematic around 10-20 distinct options. It also has issues if there is more than one set of external conditions.

Intelligent classes is a variant of the latter solution. You still have the control function, but it's much simpler. It generally would look something like:

my @list_of_classes = ( ... ); foreach my $class (@list_of_classes) { next unless $class->should_render( \%conditions1, \%conditions2, ... ); $class->render; }

You then have a bunch of classes that all provide the should_render() and render() methods. They can be related through inheritance, or not. But, what they all do is determine for themselves whether or not they should render. This means that the conditions are broken out into the units that are smaller and self-contained, thus easier to maintain. When I use this method, I get up to 50 or 60 distinct options with 2-3 sets of external conditions and have no problem.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested


In reply to Re^3: Style or Clarity? by dragonchild
in thread Style or Clarity? by periapt

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (5)
    As of 2020-10-29 17:37 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (274 votes). Check out past polls.

      Notices?