Dependency Inversion Principle -- Python Way

Charles Medcoff cmedcoff at home.com
Mon May 21 21:29:59 EDT 2001


> 1. Would you really declare class ("interface") C in python ?

You don't need to do this with Python.  However I just might do this just to
communicate the "interface" or "protocol" to other developers.  It really
depends on the code's audience.  Is this part of a library or framework that
would be used a lot by others?  A comment could also make this
clarification, but a separate class would really make it stand out.  There
is a performance trade off here by adding another level of indirection, but
that cost may or may not impact the application.  Like everything else it's
a matter of trade offs, communciation of intent, performace are just two I
can think of at the moment.

In my mind people don't spend enough time thinking about communicating with
the next developer that has to look at your code, especially in the code
itself, not in supporting documentation.

I confess that I do most of my development in statically typed langauges
(C++/Java) so maybe that's some of my own experience/bias coming through.





More information about the Python-list mailing list