Dear Monks,

I've got a question regarding KISS (keep it simple and short) in general and not necessarily related to perl.

Some time ago I was arguing with a former colleague about extending a class by inheritance: we had a class that contained an instance variable for each form element (objects) on a webpage for a multitenancy java webapplication. Now it was necessary for two tenants to have different form elements.

Since it was java and actually nobody had strong feelings about letting eclipse generate myriads of getter and setter in a single class, one (my) suggestion was:

1) No big deal... create a new base class and two inheriting classes. Write a getter for every necessary component in the base class (some might be abstract) and for the extra components the required getter in the subclasses. Advantages: you see at first glance which components are different/overridden

the colleague suggested to

2)implement a container in the old class that contained all necessary elements (objects) for this old class. And with this container, the constructor in each new subclass was responsible for removing and adding the appropriate elements. You need one class less...

I was not involved in this project so I didn't implement my solution. But nevertheless...

Solution '2' is shorter in loc but in my opinion it is not simpler. And in my opinion '1' doesn't hurt the DRY principle much more than writing getter and setter. Well... '1' is not as 'smart' as '2', you can't write additional code to show how clever you are (I might be a little bit biased...) but you can finish your task faster and imo it's easier to understand . And even if you had a common base class with this container in case '2': you would have no way to ensure that a necessary element is in this container without writing additional code.

But his arguments where that solution '1' would add too many methods and that his approach is more -uhm- generic. In my opinion his solution is like 'packing your tennis bag by packing your soccer bag first and then removing all non-tennis parts before adding the tennis-stuff...)

I still would prefer solution '1'. But I'm also interested in different point of views. So I'd like to ask my esteemed fellow monks: what's your opinion?

Thanks in advance,
k

In reply to your definition of KISS by klekker

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.