On 06/09/18 15:04, Michael F. Stemper wrote:
> Net net is that the only thing that ended up being common was the
> __init__ methods. Two of the classes have identical __init__
> methods; the third has a superset of that method. The other methods
> all have completely different implementations. This isn't due to
> poor coding, but due to the fact that what these model have
> different physical characteristics.
> Not being that familiar with object-oriented programming (I grew up
> on FORTRAN and c), I'm seeking opinions:
> 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().
What you've done is the work you would have to do in a statically-typed
language such as C++. You've been taking advantage of duck typing to
have the rest of your code not have to care about what type of load you
are modelling, but in C++ (say) you would need the superclass to supply
the type information to let the rest of your code compile.
Is it worth creating the superclass in Python? It sounds like it's a
bit marginal in your case. I'm not that seasoned in object-oriented
design either, but my yardstick would be how much common code does it
eliminate? It's a very subjective measure, but basically it's the same
subjective measure as for pulling any common code into a separate function.
Rhodri James *-* Kynesim Ltd