GithubHelp home page GithubHelp logo

solid_principles_python's Introduction

Presentation

You can find a presentation I did for the PyGeekle'22 online summit using the code examples in this project.

Requirements

Install and use Python >= 3.7 as I am using dataclasses.

The five SOLID principles are:

  • Single responsibility principle: a class should have one, and only one, reason to change.

  • Open-closed principle: software entities should be open for extension, but closed for modification. It should be possible to extend the behavior of a class without modifying it.

  • Liskov Substitution principle: subclasses should be substitutable for their superclasses.

  • Interface segregation principle: many small, client-specific interfaces are better than big general interfaces.

  • Dependency inversion principle: software entities should depend on abstractions, not in concretions.

Notes

You will find a folder inside "src" for every SOLID principle. And for each of them:

  • "wrong" folder contains code that violates the principle.
  • "right" folder contains code that satisfies the principle after some modifications of the code inside "wrong".

There is on exception. I am applying the Interface segregation Principle in order to satisfy the Liskov Substitution Principle. That's why:

  • The folder of the Liskov Substitution Principle ("LIS") just contains a subfolder named "wrong".
  • The folder of the Interface Segregation Principle ("ISP") just contains a subfolder named "right".

There is a folder called "diagrams" with the diagrams of these code examples, both in .png and .drawio formats.

To delete pycache folders:

find . -type d -name "__pycache__" -exec rm -r {} \;

I am using main.py and packages in this project.

Some resources:

To execute the examples

You should be in the root folder "Solid_Principles_Python"

To execute SRP examples:

python3 -m src.SRP.wrong
python3 -m src.SRP.right

To execute OCP examples:

python3 -m src.OCP.wrong
python3 -m src.OCP.right

To execute LIS example:

python3 -m src.LIS.wrong

To execute ISP example:

python3 -m src.ISP.right

To execute DIP examples:

python3 -m src.DIP.wrong
python3 -m src.DIP.right

solid_principles_python's People

Contributors

aldofusterturpin avatar

Stargazers

caco avatar Fernando Pratama avatar Daniel Ariz avatar Alexandru Popa avatar

Watchers

 avatar

Forkers

fer-git

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.