Giter Club home page Giter Club logo

pypatterns's Introduction

Creational

Builder

  • Separate component when object construction gets too complicated
  • Can create mutually cooperating sub-builders
  • Often has a fluent interface

Factories

  • Factory method more expressive than initializer
  • Factory can be an outside class or inner class

Prototype

  • Creation of object from an existing object
  • Requires explicit deep copy

Singleton

  • When you need to ensure just a single instance exisits
  • Easy to make with a decorator or metaclass
  • Consider using dependency injection

Structural

Adapter

  • Converts the interface you get to the interface you need

Bridge

  • Decouple abstraction from implementation

Composite

  • Allows clients to treat individual objects and compositions of objects uniformly

Decorator

  • Attach additional responsibilities to object
  • Python has functional decorator

Facade

  • Provide a single unified interface over a set of interface
  • Friendly and easy-to-use, but can provide access to low-level features

Flyweight

  • Efficiently support very large numbers of similar objects

Proxy

  • Provide a surrogate object that forwards calls to the real object while performing additional functions
  • E.g., access control, communication, logging, etc.

Behavioural

Chain of Responsibility

  • Allow components to process information/events in a chain
  • Each element in the chain refers to next element; or
  • Make a list and go through it

Command

  • Encapsulate a request into a separate object
  • Good for audit, replay, undo/redo
  • Part of CQS/CQRS

Interpreter

  • Transform textual input into object-oriented structures
  • Used by interpreters, compilers, static analysis tools, etc.
  • Compiler Theory is a separate branch of Computer Science

Iterator

  • Provide an interface for accessing elements of an aggregate object
  • __iter__/__next are stateful, but yield is much more convenient

Mediator

  • Provides mediation services between two objects
  • E.g., message passing, chat room

Memento

  • Yield tokens representing system states
  • Tokens do not allow direct manipulation, but can be used in appropriate APIs

Observer

  • Allows notifications of changes/happenings in a component

State

  • We model system by having one of a possible states and transitions between these states
  • Such a system is called a state machine
  • Special frameworks exists to orchestrate state machines

Strategy & Template Method

  • Both define a skeleton algorithm with details filled in by implementor
  • Strategy uses ordinary composition, template method uses inheritance

Visitor

  • Allows non-intrusive addition of functionality to hierarchies

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.