Design Patterns in Python
4.4 (816 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
5,431 students enrolled

Design Patterns in Python

Discover the modern implementation of design patterns in Python
4.4 (816 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
5,431 students enrolled
Created by Dmitri Nesteruk
Last updated 1/2020
English [Auto]
Current price: $69.99 Original price: $99.99 Discount: 30% off
5 hours left at this price!
30-Day Money-Back Guarantee
This course includes
  • 9 hours on-demand video
  • 1 downloadable resource
  • 22 coding exercises
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
Training 5 or more people?

Get your team access to 4,000+ top Udemy courses anytime, anywhere.

Try Udemy for Business
What you'll learn
  • Recognize and apply design patterns
  • Refactor existing designs to use design patterns
  • Reason about applicability and usability of design patterns
Course content
Expand all 107 lectures 09:11:57
+ Introduction
1 lecture 06:51

An overview of the Design Patterns in Python course.

Preview 06:51
+ The SOLID Design Principles
7 lectures 01:01:21

What are SOLID principles, where do they come from and why do we care?


A look at the Single Responsibility Principle, which states that a class should only have one reason to change. Also tied to the concept of Separation of Concerns which is basically stating the same thing.

Single Responsibility Principle

A discussion of the Open-Closed Principle, which states that classes should be open for extension, but closed for modification. In other words, you should extend functionality using interfaces and inheritance rather than jumping back into already-written/tested code and adding to it or changing it.

Open-Closed Principle

The Liskov Substitution Principle states that subtypes should be substitutable for their base types.

Liskov Substitution Principle

The Interface Segregation Principle is simple: don't throw everything in the kitchen sink into an interface because then all its users will have to implement things they do not need. Instead, split the interface into several smaller ones.

Interface Segregation Principle

Not to be confused with dependency injection, dependency inversion specifies that high-level modules should not depend on low-level ones; both should depend on abstractions. Confusing, huh?

Dependency Inversion Principle

A summary of the things we've learned in this section of the course.

+ Builder
6 lectures 33:12

A brief note about the three categories of design patterns: creational, structural and behavioral.

Gamma Categorization

An overview of the Builder design pattern.


An overview of the Builder design pattern.


A look at how several builders can work together through a common fluent interface.

Addendum: there's a small mistake in the PersonBuilder initializer; instead of =Person() it should read =None, see the attached source code for the updated example.

Preview 09:15

How to combine the functionality of several builders without breaking OCP.

Builder Inheritance
Builder Coding Exercise
1 question

A summary of the things we've learned about the Builder design pattern.

+ Factories
5 lectures 32:55

An overview of the Factory design pattern.


A constructor is a rather limited tool. A factory method adds flexibility.

Factory Method

A factory is a separate class for creating objects.


If you have a hierarchy of objects, you can have a corresponding hierarchy of factories.

Abstract Factory
Factory Coding Exercise
1 question

A summary of the things we've learned about the Factory design pattern.

+ Prototype
4 lectures 18:24

An overview of the Prototype design pattern.


Learn about deep copying and the Prototype pattern.


Well known prototypes can be put into a factory for additional convenience.

Prototype Factory
Prototype Coding Exercise
1 question

A summary of all the things we've learned about the Prototype design pattern.

+ Singleton
7 lectures 29:58

An overview of the much-maligned Singleton design pattern.


You can make an allocator that keeps returning the same object. Trouble is, the initializer still gets called more than once!

Singleton Allocator

Let's implement the Singleton as a decorator!

Note: if you don't know how Python decorators work, see the Decorator pattern lectures.

Singleton Decorator

Let's implement the Singleton using a metaclass!

Preview 02:27

A peculiar variation on the 'canonical' singleton, Monostate objects all share the same static dictionary.


Why is the Singleton problematic? What can we do to fix it?

Singleton Testability
Singleton Coding Exercise
1 question

A summary of the things we've learned about the Singleton design pattern.

+ Adapter
4 lectures 14:40

An overview of the Adapter design pattern.


Let's implement the adapter pattern — perhaps not in the most efficient manner.

Adapter (no caching)

Let's improve our Adapter implementation with some caching!

Adapter (with caching)
Adapter Coding Exercise
1 question

A summary of what we've learned about the Adapter design pattern.

+ Bridge
3 lectures 11:12

An overview of the Bridge design pattern.


Let's implement the Bridge design pattern!

Bridge Coding Exercise
1 question

A summary of the things we've learned about the Bridge design pattern.

+ Composite
4 lectures 19:39

An overview of the Composite design pattern.

Note: for more information on iteration, please consult the Iterator pattern lectures.


First, a simple example: grouping geometric shapes.

Geometric Shapes

Implementing connections between neurons and neuron layers with the Composite pattern.

Preview 10:29
Composite Coding Exercise
1 question

A summary of the things we've learned about the Composite design pattern.

+ Decorator
5 lectures 25:50

An overview of the Decorator design pattern.


To some extent, the Decorator pattern is built right into the Python language. Let's take a look at how Python's functional decorators work.

Python Functional Decorators

A classic GoF decorator is a class that gives additional functionality to the underlying class. The only problem is the original class' attributes are now inaccessible.

Classic Decorator

A dynamic decorator lets us treat the decorator as if it were the object it decorates. This works for purposes of ordinary programming, but won't work with any sort of metaprogramming.

Dynamic Decorator
Decorator Coding Exercise
1 question

A summary of the things we've learned about the Decorator design pattern.

  • Good understanding of Python
  • Familiarity with latest Python language features
  • Good understanding of object-oriented design principles
  • A computer with the latest Python release and (hopefully) an IDE

Course Overview

This course provides a comprehensive overview of Design Patterns in Python from a practical perspective. This course in particular covers patterns with the use of:

  • The latest versions of the Python programming language

  • Use of modern programming approaches: dependency injection, reactive programming and more

  • Use of modern developer tools such as JetBrains PyCharm

  • Discussions of pattern variations and alternative approaches

This course provides an overview of all the Gang of Four (GoF) design patterns as outlined in their seminal book, together with modern-day variations, adjustments, discussions of intrinsic use of patterns in the language.

What are Design Patterns?

Design Patterns are reusable solutions to common programming problems. They were popularized with the 1994 book Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, John Vlissides, Ralph Johnson and Richard Helm (who are commonly known as a Gang of Four, hence the GoF acronym).

The original book was written using C++ and Smalltalk as examples, but since then, design patterns have been adapted to every programming language imaginable: C#, Java, Python and even programming languages that aren't strictly object-oriented, such as JavaScript.

The appeal of design patterns is immortal: we see them in libraries, some of them are intrinsic in programming languages, and you probably use them on a daily basis even if you don't realize they are there.

What Patterns Does This Course Cover?

This course covers all the GoF design patterns. In fact, here's the full list of what is covered:

  • SOLID Design Principles: Single Responsibility Principle, Open-Closed Principle, Liskov Substitution Principle, Interface Segregation Principle and Dependency Inversion Principle

  • Creational Design Patterns: Builder, Factories (Factory Method and Abstract Factory), Prototype and Singleton

  • Structrural Design Patterns: Adapter, Bridge, Composite, Decorator, Façade, Flyweight and Proxy

  • Behavioral Design Patterns: Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method and Visitor

Who Is the Course For?

This course is for Python developers who want to see not just textbook examples of design patterns, but also the different variations and tricks that can be applied to implement design patterns in a modern way. For example, the use of decorators and metaclasses allows us to prepackage certain patterns for easy re-use.

Presentation Style

This course is presented as a (very large) series of live demonstrations being done in JetBrains PyCharm and presented using the Kinetica rendering engine. Kinetica removes the visual clutter of the IDE, making you focus on code, which is rendered perfectly, whether you are watching the course on a big screen or a mobile phone. 

Most demos are single-file, so you can download the file attached to the lesson and run it in PyCharm, IDLE or another IDE of your choice.

This course does not use UML class diagrams; all of demos are done via live coding.

Who this course is for:
  • Software engineers
  • Designers
  • Architects