Skip to content

ELC/python-design-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Design Patterns

This repo is a collection of non-trivial examples of several design patterns implemented in different ways. Its aim is to contrast traditional (i.e. GoF) design patterns with more Pythonic equivalents, metrics about each implementation are also provided.

The notion of being Pythonic is indeed subjective and it is used in the sense of leveraging built-in Python features such as Protocols, Callable classes, closures, partial evaluation, generators, decorators, first-class functions and so on.

Each pattern has an independent README linked below with a guide to highlight differences between implementation details.

Why This repo?

The python-patterns repo already provides a succint and clear way to implement idiomatic patterns in Python.

This repo focuses on showing different ways to implement the same pattern, including the traditional Java/C/C# like implementation to provide the reader with a comparison. Moreover metrics are added to each implementation to better contrast solutions.

Patterns

Behavioural

Creational

Structural

Metrics

The metrics to be used are:

  • Cyclomatic Complexity: is equal to the number of linearly independent paths through the code.
  • Maintainability Index: is calculated as a factored formula consisting of SLOC, Cyclomatic Complexity and Halstead volume.
  • LOC: The total number of lines of code. It does not necessarily correspond to the number of lines in the file.
  • LLOC: The number of logical lines of code. Every logical line of code contains exactly one statement.
  • SLOC: The number of source lines of code - not necessarily corresponding to the LLOC.

To generate the metrics, use the following commands from the radon library:

python -m radon raw . -s -O stats.md
python -m radon mi . -s -j -O mi.json
python -m radon cc . -s --show-closures --total-average --md -O complexity.md

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages