Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,27 @@ You can also run `flake8` or `pytest` commands manually. Examples can be found i
## Contributing via issue triage [![Open Source Helpers](https://www.codetriage.com/faif/python-patterns/badges/users.svg)](https://www.codetriage.com/faif/python-patterns)

You can triage issues and pull requests which may include reproducing bug reports or asking for vital information, such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to python-patterns on CodeTriage](https://www.codetriage.com/faif/python-patterns).


## 🚫 Anti-Patterns

This section lists some common design patterns that are **not recommended** in Python and explains why.

### 🧱 Singleton
**Why not:**
- Python modules are already singletons — every module is imported only once.
- Explicit singleton classes add unnecessary complexity.
- Better alternatives: use module-level variables or dependency injection.

### 🌀 God Object
**Why not:**
- Centralizes too much logic in a single class.
- Makes code harder to test and maintain.
- Better alternative: split functionality into smaller, cohesive classes.

### 🔁 Inheritance overuse
**Why not:**
- Deep inheritance trees make code brittle.
- Prefer composition and delegation.
- “Favor composition over inheritance.”

14 changes: 6 additions & 8 deletions patterns/creational/builder.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""
*What is this pattern about?
What is this pattern about?
It decouples the creation of a complex object and its representation,
so that the same process can be reused to build objects from the same
family.
This is useful when you must separate the specification of an object
from its actual representation (generally for abstraction).

*What does this example do?

What does this example do?
The first example achieves this by using an abstract base
class for a building, where the initializer (__init__ method) specifies the
steps needed, and the concrete subclasses implement these steps.
Expand All @@ -22,16 +21,15 @@ class for a building, where the initializer (__init__ method) specifies the
In general, in Python this won't be necessary, but a second example showing
this kind of arrangement is also included.

*Where is the pattern used practically?

*References:
https://sourcemaking.com/design_patterns/builder
Where is the pattern used practically?
See: https://sourcemaking.com/design_patterns/builder

*TL;DR
TL;DR
Decouples the creation of a complex object and its representation.
"""



# Abstract Building
class Building:
def __init__(self) -> None:
Expand Down
3 changes: 2 additions & 1 deletion patterns/creational/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def get_localizer(language: str = "English") -> Localizer:
"Greek": GreekLocalizer,
}

return localizers[language]()
return localizers.get(language, EnglishLocalizer)()



def main():
Expand Down