Python Patterns
Help the project financially:
- Donate: https://smartlegion.github.io/donate/
- Yandex Money: https://yoomoney.ru/to/4100115206129186
- PayPal: https://paypal.me/smartlegioner
- LiberaPay: https://liberapay.com/smartlegion/donate
- Visa: 4048 0250 0089 5923
Short description:
python-patterns - A collection of design patterns and idioms in Python (With tests!).
Current Patterns
Creational Patterns:
Pattern | Description | Tests |
---|---|---|
Abstract Factory | use a generic function with specific factories | test |
Builder | instead of using multiple constructors, builder receives parameters and returns constructed objects | test |
Factory Method | delegate a specialized function/method to create instances | test |
Prototype | use a factory and clones of a prototype for new instances (if instantiation is expensive) | test |
Singleton | Ensures that the class has only one instance, and provides a global access point to it. | test |
Structural Patterns:
Pattern | Description | Tests |
---|---|---|
Adapter | converts the interface of one class to the interface of another that clients expect. | test |
Bridge | a client-provider middleman to soften interface changes | test |
Composite | lets clients treat individual objects and compositions uniformly | test |
Decorator | wrap functionality with other functionality in order to affect outputs | test |
Facade | use one class as an API to a number of others | test |
Flyweight | transparently reuse existing instances of objects with similar/identical state | test |
Proxy | an object funnels operations to something else | test |
Behavior Patterns:
Pattern | Description | Tests |
---|---|---|
Blackboard | architectural model, assemble different sub-system knowledge to build a solution, AI approach - non gang of four pattern. | test |
chain_of_responsibility | apply a chain of successive handlers to try and process the data. | test |
command | bundle a command and arguments to call later. | test |
interpreter | a behavioral design pattern that solves a frequently encountered but subject to change problem. | test |
iterator | traverse a container and access the container's elements. | test |
mediator | an object that knows how to connect other objects and act as a proxy. | test |
memento | generate an opaque token that can be used to go back to a previous state. | test |
observer | provide a callback for notification of events/changes to data. | test |
state | logic is organized into a discrete number of potential states and the next state that can be transitioned to. | test |
strategy | selectable operations over the same data. | test |
template_method | defines the basis of the algorithm and allows subclasses to override some of the steps in the algorithm, without changing its structure as a whole. | test |
visitor | invoke a callback for all items of a collection. | test |
Help:
Requirements:
- python 3.6+
For run tests:
-
pytest
pip3 install pytest
pytest -v
-
pytest-cov
pip3 install pytest-cov
pytest --cov
Disclaimer of liability:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Links:
- Github: https://github.com/smartlegion/
- Url: https://smartlegion.github.io/
- PyPi: https://pypi.org/user/smartlegion/
- Donate: https://smartlegion.github.io/donate/
Information:
Licensed under the terms of the BSD 3-Clause License
==========================================================
Copyright (c) 2018-2021, A.A Suvorov; All rights reserved.
==========================================================