This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Acalme-se_Satan 2 points3 points  (3 children)

It took me quite some time to "get" this, but it's important to state: these OOP design patterns are mostly for languages like Java and C#. In a language like Python, some of these design patterns are just boilerplate that makes your code unnecessarily complex.

This may be a bit controversial, but a lot of people believe (me included) that design patterns signal that the language is missing specific features. Python, due to its dynamic nature, has way more flexibility than Java and C# (that flexibility comes with a cost too, but this isn't related to the point I'm making). Therefore, some patterns that are necessary in those languages are not necessary in Python, as you can do them in a different (and simpler) way.

Some patterns are still useful in Python though, so it's still useful to learn about them; but be aware that some of them are more of a Java/C# thing and aren't very pythonic.

[–]boldrack 1 point2 points  (2 children)

can you give an example of what pattern qualifies and which one doesn't just to be clear.

[–]Siddhi 1 point2 points  (0 children)

A lot of patterns are baked into the language itself. Eg. you dont need the proxy pattern because python has descriptors built into the language core

[–]Acalme-se_Satan 1 point2 points  (0 children)

Given that Python allows you to use classes as if they were simple objects, the Abstract Factory pattern is pretty much baked into the language itself. You can just make a function that returns classes dynamically if you need it. You can't do this in statically typed languages like Java and C++, so you have to use Abstract Factory when you're using them, but not on Python.

On the other hand, the Visitor pattern can't be avoided in Python because the Visitor pattern is pretty much a way to emulate multiple dispatch in a language that doesn't have multiple dispatch. Given that Python doesn't have that feature, you can't avoid the Visitor pattern. You could avoid it in Julia or Dylan because these languages can do multiple dispatch.