Object-oriented philosophy

Michael F. Stemper michael.stemper at gmail.com
Thu Sep 6 16:31:03 EDT 2018


On 2018-09-06 12:32, Stefan Ram wrote:
> "Michael F. Stemper" <michael.stemper at gmail.com> writes:
>> Is there really any benefit to this change? Yes, I've eliminated
>> some (a few lines per class) duplicate code. On the other hand,
>> I've added the parent class and the (probably small, but not
>> non-existent) overhead of invoking super().
> 
>   You have a operation »Resistance( V )«.

Mathematically, that's an operation, I suppose. I tend to think of it
as either a function or a method.

>   OOP is advantageous if you can anticipate that you will want
>   to extend operations for other types.

Since the way that each operation (aside from __init__) differs
from one load type to the next, is there really an advantage?

>   I.e., if you anticipate a new type »ConstantVoltage«, you

Actually, although the possibility of other load models exists,
ConstantVoltage() would be impossible, since these models are
all defined based on the behavior of the load *in response to a
change in voltage*. But your point is well-taken, which is part
of why I considered doing inheritance.

>   can add an operation »Resistance( V )« for this new type
>   without changing the existing definitions (open-closed
>   principle).
> 
>   Non-OOP is advantageous if you can anticipate that you will
>   want to add new operations for the existing types.
> 
>   (Non-OOP means in this case that you have a single
>   definition of a function »Resistance( entity, V )« which
>   contains an internal multiple branch on the type of the
>   entity.)

To be honest, that sounds painful and hard to maintain. Of course,
back in my F77 days, it would have been the only option.

Thanks for your time.

-- 
Michael F. Stemper
Why doesn't anybody care about apathy?



More information about the Python-list mailing list