Classic OOP in Python

Todd toddrjen at gmail.com
Thu Jun 18 07:07:53 EDT 2015


On Thu, Jun 18, 2015 at 1:03 PM, Fabien <fabien.maussion at gmail.com> wrote:

> On 06/17/2015 11:16 PM, sohcahtoa82 at gmail.com wrote:
>
>> You don't need interfaces with Python.  Duck typing makes that all
>> possible.
>>
>
> Yes, but I also like interfaces (or in python: mimicked interfaces with
> NotImplementedError) for their clarity and documentation purposes.
>
> 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)
>
>
I think this is what abstract base classes are for in Python.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150618/021c025d/attachment.html>


More information about the Python-list mailing list