klekker has asked for the wisdom of the Perl Monks concerning the following question:
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 to2)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,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: your definition of KISS
by JavaFan (Canon) on Feb 07, 2012 at 22:40 UTC | |
by klekker (Pilgrim) on Feb 08, 2012 at 09:31 UTC | |
|
Re: your definition of KISS
by wrog (Friar) on Feb 07, 2012 at 22:25 UTC | |
by klekker (Pilgrim) on Feb 08, 2012 at 09:10 UTC | |
|
Re: your definition of KISS
by Anonymous Monk on Feb 07, 2012 at 17:04 UTC | |
by klekker (Pilgrim) on Feb 07, 2012 at 20:51 UTC | |
|
Re: your definition of KISS
by locked_user sundialsvc4 (Abbot) on Feb 07, 2012 at 21:30 UTC | |
by klekker (Pilgrim) on Feb 08, 2012 at 09:49 UTC |