Classic OOP in Python

Chris Angelico rosuav at gmail.com
Thu Jun 18 07:43:28 EDT 2015


On Thu, Jun 18, 2015 at 9:03 PM, Fabien <fabien.maussion at gmail.com> wrote:
> Would you consider the following kind of program "unpythonic"?
>
> class MovingObject(object):
>     """Great doc about what a moving object is"""
>
>     def move(self):
>         """Great doc about move"""
>         raise NotImplementedError()
>
> class Dog(MovingObject):
>     def move(self):
>         print "Dog is moving"
>
> class Car(MovingObject):
>     def move(self):
>         print "Car is moving"
>
> (Disclaimer: I learned OOP with Java)

Now try extending the concept to two, three, or four such interfaces.
Files can be moved, opened, copied, and unlinked. Should they share
any sort of interface with dogs, boxes, handwriting, and railway
carriages? It's much better to simply define the attributes of each
object separately; most non-trivial cases don't involve simple methods
with no additional arguments, and the chances of an incompatibility
(or worse, a forced compatibility) go up.

ChrisA



More information about the Python-list mailing list