smartlegionlab / python_patterns

A collection of design patterns and idioms in Python.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python Patterns

A collection of design patterns and idioms in Python.


Current Patterns

Creational Patterns:

Pattern Description
Abstract Factory use a generic function with specific factories
Builder instead of using multiple constructors, builder receives parameters and returns constructed objects
Factory Method delegate a specialized function/method to create instances
Prototype use a factory and clones of a prototype for new instances (if instantiation is expensive)
Singleton Ensures that the class has only one instance, and provides a global access point to it.

Structural Patterns:

Pattern Description
Adapter converts the interface of one class to the interface of another that clients expect.
Bridge a client-provider middleman to soften interface changes
Composite lets clients treat individual objects and compositions uniformly
Decorator wrap functionality with other functionality in order to affect outputs
Facade use one class as an API to a number of others
Flyweight transparently reuse existing instances of objects with similar/identical state
Proxy an object funnels operations to something else

Behavior Patterns:

Pattern Description
Blackboard architectural model, assemble different sub-system knowledge to build a solution, AI approach - non gang of four pattern.
Chain Of Responsibility apply a chain of successive handlers to try and process the data.
Command bundle a command and arguments to call later.
Interpreter a behavioral design pattern that solves a frequently encountered but subject to change problem.
Iterator traverse a container and access the container's elements.
Mediator an object that knows how to connect other objects and act as a proxy.
Memento generate an opaque token that can be used to go back to a previous state.
Observer provide a callback for notification of events/changes to data.
State logic is organized into a discrete number of potential states and the next state that can be transitioned to.
Strategy selectable operations over the same data.
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.
Visitor invoke a callback for all items of a collection.

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.

About

A collection of design patterns and idioms in Python.

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 100.0%