Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 10th, 2003, 11:18 AM
Cuboidz Cuboidz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 11 Cuboidz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question 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:

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.

Reply With Quote
  #2  
Old September 10th, 2003, 01:55 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 12
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Does interface-only inheritance make sense in Python ?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap