Object-oriented philosophy

Michael F. Stemper michael.stemper at gmail.com
Sat Sep 8 10:05:36 EDT 2018


On 2018-09-06 16:04, Stefan Ram wrote:
> "Michael F. Stemper" <michael.stemper at gmail.com> writes:
>>> 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.
> 
>   I deliberately did not use neither "a function" nor
>   "a method" because by "operation" I meant something else,
>   I meant the three methods "Resistance( V )« (literally,
>   »Resistance( self, V )«) of your three classes (and possible
>   of other model classes added in the future) /viewed together
>   as an abstract concept/ "get the resistance under 'this'
>   model", independent of any specific load model.

Took me two days, but I finally grok what you said.

>>> 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?
> 
>   The implementation differs, but not the interface and meaning.
> 
>   The advantage is that you can extend this operation for
>   additional types /without/ modifying the existing implementations
>   (the open-closed principle!). Whereas with a single
>   procedure in a non-OOP language, you would have to /modify/
>   (error-prone!) an existing procedure.

And another advantage has surfaced through this discussion. Even though
the common code was only half-a-dozen lines or so, it changed three
times due to suggestions made in this thread. Abstracting it to a
parent meant that I only had to implement and test each of these changes
in one place, rather than three.

>>> (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.
> 
>   Well, non-OOP is /not/ obsolete. It just has other specific
>   advantages and disadvantages. It could be advantageous,
>   when one adds new operations more often than new types.

To misquote "Chico Escuela", "Fortran been berry, berry good to me."

-- 
Michael F. Stemper
A preposition is something you should never end a sentence with.



More information about the Python-list mailing list