Student Login

3 ways OOP in Python is different

Do the normal design patterns apply to Python?

This is a question worth asking. I own thick, heavy books with the phrase "design pattern" in their title. They're good books. I'm glad I have them, and I'm glad I've read them.

But:

They're mostly for languages like Java and C++. That's what their example code is written in. Not Python.

It turns out: what's in these books DOES apply to Python.

But since Python's features are different from those other languages... those design patterns, and object-oriented programming in general, have a different flavor.

Python flavored!

Here's a few ways OOP is different in Python:

More Dynamic Inheritance

Inheritance is great, when you know how to use it right. And pretty horrible when you use it wrong.

There's sometimes a fine line. And dancing on that line with style, instead of falling face-first on the frickin' floor, depends on how you use the details of the language.

Here's what's cool with Python: since it's more dynamic (in several senses of the word), you can do things with inheritance that don't have an equivalent in other languages. And some of these are pretty useful.

Properties

Getters and setters. Know what I mean?

Throw out everything you know about them from Java Sharp Plus Plus. Python does them in a completely different way from any other language out there.

(And it actually helps immensely with refactoring.)

Abstract Classes

Some languages have virtual methods, and interfaces, and abstract classes.

Without going into the details, I'll just say Python does this completely differently too. And from what people tell me, it's basically never explained well.

So that's three ways OOP in Python is different. There are more, of course.

For Teams Bootcamp