Giter Club home page Giter Club logo

design-patterns's Introduction

design-patterns

License: MIT Code style: black

Some of the most common design patterns implemented in Python.

⚠️ READ THIS ⚠️

Design patterns are spoonfeed material for brainless programmers incapable of independent thought, who will be resolved to producing code as mediocre as the design patterns they use to create it.

Christer Ericson, VP of Technology at Activision Central Tech.

When I started programming, I thought that a serious programmer should have to know all major design patterns described in the book Design Patterns: Elements of Reusable Object-Oriented Software, and religiously write code that would follow them.

Over time, I realized that only a few of these patterns are actually good, most of them are bad, some others are completely unnecessary, especially in a dynamic language like Python. In fact, I don't recall having to use most of them, except for maybe Decorator, Observer and Strategy.

Before reading the code in this repository, I suggest you have a look at these resources to understand whether a particular design pattern suits your use-case or not:

Installation

This project uses pyenv and pyenv-virtualenv to manage the Python virtual environment, and poetry to manage the project dependencies.

If you don't have python 3.x.x, you have to install it. For example, I'm using 3.7.9.

pyenv install 3.7.9

Create a virtual environment and activate it.

pyenv virtualenv 3.7.9 design_patterns
pyenv activate design_patterns

Install all the dependencies from the poetry.lock file.

poetry install

Usage

Every python file contains an implementation of a design pattern and a simple example that can help you understand where the pattern might be useful.

For example

python observer.py
python strategy.py
# etc...

Tests

If you want you can run all tests with:

poetry run pytest --verbose

You can also test the MVC pattern with:

cd mvc
poetry run python model_view_controller.py

# or simply
python mvc/model_view_controller.py

Troubleshooting

If you use pyenv and get the error "No module named '_ctypes'" on Ubuntu, you are probably missing the libffi-dev package. See this answer.

If you get Error: pg_config executable not found. on Ubuntu, install the libpq-dev package. See here.

design-patterns's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

design-patterns's Issues

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.