Classic OOP in Python
sohcahtoa82 at gmail.com
sohcahtoa82 at gmail.com
Wed Jun 17 17:16:18 EDT 2015
On Wednesday, June 17, 2015 at 12:21:32 PM UTC-7, Jason P. wrote:
> Hello Python community.
>
> I come from a classic background in what refers to OOP. Mostly Java and PHP (> 5.3). I'm used to abstract classes, interfaces, access modifiers and so on.
>
> Don't get me wrong. I know that despite the differences Python is fully object oriented. My point is, do you know any book or resource that explains in deep the pythonic way of doing OOP?
>
> For example, I'm gonna try to develop a modest application from ground up using TDD. If it had been done in Java for instance, I would made extensive use of interfaces to define the boundaries of my system. How would I do something like that in Python?
>
>
> Many thanks!
You don't need interfaces with Python. Duck typing makes that all possible. This is perfectly valid:
class Dog(object):
def move(self):
print "Dog is moving"
class Car(object):
def move(self):
print "Car is moving"
things = [Dog(), Car()]
for thing in things:
thing.move()
Despite Dog and Car being completely different classes with no relationship with each other, the code runs just fine.
More information about the Python-list
mailing list