|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
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:
Code:
class Shape:
def draw(self): pass
class Circle(Shape):
def draw(self):
print "Drawing Circle"
class Rectangle(Shape):
def draw(self):
print "Drawing Rectangle"
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. 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. |
|
#2
|
|||
|
|||
|
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.
Code:
class Shape: pass This is often useful for exceptions, I find, but not much else. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Does interface-only inheritance make sense in Python ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|