On Saturday, January 7, 2017 at 7:03:10 AM UTC-5, Edward K. Ream wrote:
>
> On Sat, Jan 7, 2017 at 1:40 AM, rengel <[email protected]> 
> wrote:
>
>> Is there any reason why the classes 'GlobalConfigManager' and 
>> 'LocalConfigManager' in leoConfig.py contain so much duplicate code and why 
>> these classes don't have a common superclass?
>>
>
> ​It's not always the case that putting common code in a superclass is the 
> simplest, clear​
> ​est code.
>

Sorry, that's kind of a "go away and don't bother me answer".  In fact, 
there is an important principle involved, one that can not be reduced to a 
formula.

I have often spoken of Glenford Meyers 
<https://en.wikipedia.org/wiki/Glenford_Myers> as a crucial influence in my 
thinking, especially his book, *Reliable Software Through Composite Design*. 
New York: Petrocelli/Charter, 1975.

This book was written before there was such a thing as object-oriented 
programming, but it's principles are, imo, more important than OOP.

The idea that sticks in my mind is that classes, methods and functions must 
have a single, clear, unified, purpose.  They shouldn't have multiple 
purposes, and for sure the purpose of a piece of code should *not* just be 
to reduce code duplication.

The application of this principle is to define a base class only if that 
class means something *all by itself*.  Yes, you can say that base classes 
always mean "the code common to other classes", but that's not good enough, 
imo.

Another way of looking at this particular question is that the duplicate 
code in the two config classes are simply "accidental".  Another way of 
looking at these two classes is that it's simpler, in Leo, to have them be 
independent.

Again, these are judgement calls, but in this case I think the judgment is 
justified.  YMMV.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to