In this series of blog articles, I'm going to review the Python design patterns found here:
github.com/faif/python-patterns
I chose this repository because it seems to be one of the most popular so it should be a good place to start. The main objective of this analysis is to help people coming to Python and more advanced users to add more structure to their code.
Design patterns have been out there for a while and if you have been working long enough, you would have heard or even read the GOF book. Normally, patterns are better prepared for slightly different languages that include concepts like interfaces and private objects/methods, etc.
If you're new to Python or if you're coming from a different language like Java or C#, it can be difficult to understand the Pythonic way to adapt these patterns (at least that happened to me). This series of articles should help with that.
I'm going to follow the structure of the repository and will add the Python, Design Pattern and the Design Pattern type (e.g. structural) tags to each post so they are easy to find.
NB: these articles are not about judging whether the pattern is the right way to solve the problem or not. That is a very complex problem that depends on many variables. Typically if you have a team of very experienced Python developers, you can choose more elegant solutions such as Python decorators, generators, etc. But if you have a group of developers coming from Java or C# or less experienced in general, "flatter" structures will help you to maintain the code and support it better.
As I said above, I will explain each design pattern (from the Python point of view). Then, I'll give examples of when to use each pattern and if it make sense, I'll also mention thinks to watch for.
github.com/faif/python-patterns
I chose this repository because it seems to be one of the most popular so it should be a good place to start. The main objective of this analysis is to help people coming to Python and more advanced users to add more structure to their code.
Design patterns have been out there for a while and if you have been working long enough, you would have heard or even read the GOF book. Normally, patterns are better prepared for slightly different languages that include concepts like interfaces and private objects/methods, etc.
If you're new to Python or if you're coming from a different language like Java or C#, it can be difficult to understand the Pythonic way to adapt these patterns (at least that happened to me). This series of articles should help with that.
I'm going to follow the structure of the repository and will add the Python, Design Pattern and the Design Pattern type (e.g. structural) tags to each post so they are easy to find.
NB: these articles are not about judging whether the pattern is the right way to solve the problem or not. That is a very complex problem that depends on many variables. Typically if you have a team of very experienced Python developers, you can choose more elegant solutions such as Python decorators, generators, etc. But if you have a group of developers coming from Java or C# or less experienced in general, "flatter" structures will help you to maintain the code and support it better.
As I said above, I will explain each design pattern (from the Python point of view). Then, I'll give examples of when to use each pattern and if it make sense, I'll also mention thinks to watch for.