Là một dự án backend, faif/python-patterns đã đạt 43.1k sao trên GitHub, ngôn ngữ Python. A collection of design patterns/idioms in Python
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
A collection of design patterns and idioms in Python.
Remember that each pattern has its own trade-offs. And you need to pay attention more to why you're choosing a certain pattern than to how to implement it.
Creational Patterns
Patterns that deal with object creation — abstracting and controlling how instances are made.
graph LR
Client -->|requests object| AbstractFactory
AbstractFactory -->|delegates to| ConcreteFactory
ConcreteFactory -->|produces| Product
Builder -->|step-by-step| Director
Director -->|returns| BuiltObject
FactoryMethod -->|subclass decides| ConcreteProduct
Pool -->|reuses| PooledInstance
Pattern
Description
abstract_factory
use a generic function with specific factories
borg
a singleton with shared-state among instances
builder
instead of using multiple constructors, builder object receives parameters and returns constructed objects
factory
delegate a specialized function/method to create instances
lazy_evaluation
lazily-evaluated property pattern in Python
pool
preinstantiate and maintain a group of instances of the same type
prototype
use a factory and clones of a prototype for new instances (if instantiation is expensive)
Structural Patterns
Patterns that define how classes and objects are composed to form larger, flexible structures.
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.”
Videos
Design Patterns in Python by Peter Ullrich
Sebastian Buczyński - Why you don't need design patterns in Python?
You Don't Need That!
Pluggable Libs Through Design Patterns
Contributing
When an implementation is added or modified, please review the following guidelines:
Docstrings
Add module level description in form of a docstring with links to corresponding references or other useful information.
Add "Examples in Python ecosystem" section if you know some. It shows how patterns could be applied to real-world problems.
facade.py has a good example of detailed description, but sometimes the shorter one as in template.py would suffice.
Python 2 compatibility
To see Python 2 compatible versions of some patterns please check-out the legacy tag.
Update README
When everything else is done - update corresponding part of README.
Travis CI
Please run the following before submitting a patch:
If you have a bash-compatible shell, use ./lint.sh to run formatting,
linting, type checking, and tests.
Development dependencies are pinned in Pipfile.lock. After changing
Pipfile, activate a Python 3.10 virtual environment and run make lock to
regenerate it.
Contributing via issue triage
You can triage issues and pull requests on CodeTriage.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/faif/python-patterns là nguồn chính thức.
faif/python-patterns có những chủ đề gì?
GitHub topics của faif/python-patterns: "design-patterns", "idioms", "python". TopGit xếp repo vào nhóm Backend.
faif/python-patterns có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho faif/python-patterns. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
faif/python-patterns có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho faif/python-patterns. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
faif/python-patterns còn đang phát triển không?
Commit gần nhất trên faif/python-patterns là 14 ngày trước (theo timestamp GitHub). Repo có 7.0k fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về python-patterns?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về python-patterns.