Understand Design Patterns with Simple Pythonic Code

Tetsuya Hirata
1 min readJun 6, 2021
Photo by Storme22k on Pixabay

A design pattern is based on an Object Oriented Design(OOP) paradigm. Through facing the common issues related to objects, the common design pattern is extracted to solve them. The design pattern is categorized into 3 sub-classifications based on kind of problem they solve.

1)Creational Patterns:
The patterns of object creation and instance initialization
- Singleton(vs IBorg)
- Factory Method
- Abstract Factory Method
- Builder
- Prototype

2)Structural Patterns:
The patterns to assemble objects and classes into larger structures while keeping these structures flexible and efficient
- Adapter (=warraper)
- Bridge
- Composite
- Decorator
- Proxy

3)Behavioural Patterns:
The common communication patterns between objects
- Mediator
- Observer
- State
- Strategy
- Template Method

This article summarizes the code of each patterns in simple pythonic way. The code is referring to several web resources and books. If you understand more clearly practices, I recommend to read this book.

Python in Practice: Create Better Programs Using Concurrency, Libraries, and Patterns

Creational Patterns

Singleton

Factory Method

Abstract Factory Method

Builder

Prototype

Structural Patterns

Adapter (=warraper)

Bridge

Composite

Decorator

Proxy

Behavioural Patterns

Mediator

Observer

State

Strategy

Template Method

--

--

Tetsuya Hirata

Software engineer working mostly at the intersection of data science and engineering. @JesseTetsuya