It would depend upon 2 things:

  • How complex is the validation criteria
  • What, if any relationship is there between the four classes/attributes

    Perhaps the best test of the relationship is:

  • If the validation criteria changes for one of the attributes, will it change for all of them? Always?

    If the answer to that question is yes, which implies that the four attributes represent the same entity in the four classes, then it wold make sense to factor that code into a common place.

    Maybe as a utility subroutine called from the inline validation code. But then again, if they are all the same thing, maybe they should be a separate class? That would I guess depend upon whether they have any other behaviours besides existing and requiring validation.

    However, if these are completely unrelated fields that just happen to require similar validation criteria--as, perhaps, required to be lower case--then I would not use a common validation routine.

    To do so leaves you open to someone changing the validation routine to accomodate future changes in one field and unwittingly breaking the other three unrelated classes.

    In either case, whether done manually, or through a subroutine, the best place for it is right there after the value is assigned.


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.

    In reply to Re^17: Assignable Subroutines by BrowserUk
    in thread Assignable Subroutines by dragonchild

    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.