Just to add confusion >:) - another possible approach might be to have a Semantic Checking base class that contains any common code between the way an Entry and a Dictionary checks for valid semantics. Maybe Entry will use this class directly, while Dictionary will use a specialized sub-class.

As Masem said, there is nothing wrong with different classes sharing the same method names. That's usually good design.

I recommend designing the three different Semantic classes, if you find any substantial amount of commonality, look into interitance. It seems to me that the Entry checker is the simple one, Dictionary checker does a bit more work, and then your last checker does even more work. This might be a good candidate for aggregation, where the Dictionary checker passes off some of it's responsibilty to the Entry checker, maybe. TIMTOWTDI, especially in OO design.

I heard Flyweight pattern mentioned in the chatter yesterday. Here is a brief explanation taken from Design Patterns (the GoF book):

In other words, the character code being stored in a given flyweight is called intrinsic state, it is information independent of the flyweights context - whereas the info about the character's position and font are passed to the flyweight object by the client when it need them. This information depends upon the flyweight's context - this is known as extrinsic state.

So, do you need to implement the Flyweight pattern on this problem? Probably not - the Flyweight would only be good if you had started with it, and had more than 3 objects in question. So at this point, i recommend going ahead with your original idea, and call each method from Entry, Dictionary, etc. the same - semcheck() works for me. ;)

Every problem is different, and as such, each implementation will have subtle differences. Does code A belong in object foo or bar. Try both and see which is the most flexible, and which is simplest.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

In reply to (jeffa) Flyweight Pattern by jeffa
in thread Question to OO Masters (about Style) by PetaMem

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.