September 10th, 2003, 11:18 AM
Does interface-only inheritance make sense in Python ?
In statically typed languages like Java & C++ you _need_ to use inheritance to accomplish polymorphism, so people have grown accustomed to doing this. But in python you can have polymorphism whenever 2 objects have a certain method in common, regardless of their type. Yet I often encounter things like this:
This doesn't make any sense to me. Circle & Rectangle can be substituted polymorphically without inheriting from Shape, so I think it is unnecessary to clutter your code with practices from statically typed languages.
def draw(self): pass
print "Drawing Circle"
print "Drawing Rectangle"
Python offers both interface and implementation inheritance at the same time, something that should be used appropriately (When you need to inherit the interface AND the implementation).
Anyway, that's what I think, feel free to prove me wrong
Last edited by Cuboidz; September 10th, 2003 at 11:27 AM.
September 10th, 2003, 01:55 PM
If you aren't inheriting actual methods from the parent class, I find that using the same conventions in Python is unnecessary. If you really want, you can do it, but it's ugly. If you feel the need to share a common parent in that case, just make it an empty class.
This is often useful for exceptions, I find, but not much else.