Software Design Patterns with types in Python.
Project description
A Python package with common Software Design Patterns.
build |
|
---|---|
package |
|
code quality |
Overview
This repository hosts the open-source code of the Software Patterns project. The project’s main component is the software-patterns python package hosted on Pypi at https://pypi.org/project/software-patterns It also features online Documentation Pages hosted at https://software-patterns.readthedocs.io/ and a public CI workflow hosted on CircleCI.
What are Software Design Patterns?
Software Engineers are employing various designs and solutions to solve their problems. The emerging (software) patterns, among the code solutions, targeting reoccuring problems have been studied and formalized in terms of how they are used, what problem they solve and why they are a fit candidate to solve it. These code designs, which are frequently found in various code bases, are known as Software Design Patterns.
The software-patterns package exposes a set of Python Classes that allow convient usage of common Software Design Patterns.
Design Patterns implemented:
Notification (aka Broadcast/Listener pattern)
Object Pool (aka Memoize)
Classes Registry (aka Abstract Factory)
Proxy
Installation
Install from the Pypi server:
pip install software-patterns
Quickstart
Example code to use the factory pattern in the form of a (sub) class registry:
from software_patterns import SubclassRegistry
class MyClassRegistry(metaclass=SubclassRegistry):
pass
@MyClassRegistry.register_as_subclass('a')
class ClassA:
def __init__(self, number):
self.attr = number
@MyClassRegistry.register_as_subclass('b')
class ClassB:
def __init__(self, number):
self.attr = number - 1
assert MyClassRegistry.subclasses == {'a': ClassA, 'b': ClassB}
instance_a = MyClassRegistry.create('a', 10)
assert type(instance_a) == ClassA
assert instance_a.attr == 10
assert isinstance(instance_a, ClassA)
instance_b = MyClassRegistry.create('b', 10)
assert type(instance_b) == ClassB
assert instance_b.attr == 9
assert isinstance(instance_b, ClassB)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file software_patterns-2.0.0.tar.gz
.
File metadata
- Download URL: software_patterns-2.0.0.tar.gz
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.0 importlib_metadata/5.0.0 packaging/21.3 pkginfo/1.8.3 requests/2.28.1 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81775f0514e75b407371f109db12e49facc3daee30aa77a0d1d0578475dd3121 |
|
MD5 | a6ed97d995726e0d25b757dea3404cd5 |
|
BLAKE2b-256 | e70a20a11e3512f698a200751ade194307ad402f3c9ac80c2117a13803eee20b |
File details
Details for the file software_patterns-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: software_patterns-2.0.0-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.0 importlib_metadata/5.0.0 packaging/21.3 pkginfo/1.8.3 requests/2.28.1 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb9dff03e74e3b288f3e5d09b68cb277145ea49d90b3a368f5b16cf767f339df |
|
MD5 | 66e15a360eba809bb9509f2340511974 |
|
BLAKE2b-256 | d2386b22378c5d2e71bea287cd955741cd0c7096e791870e14613182f6a75c92 |