Python Design Patterns
Section 1: Design Pattern
Warm Up
1.1 The Course Overview
❶ This
video provides an overview of the entire course.
1.2 What Are Design Patterns?
Understand what design patterns are and why they are useful.
❶ Explore the concept of a design pattern
❷ Look at where design patterns originate from
❸ Understand the uses and pitfalls of design patterns
1.3 Design Pattern
Classification
Introduce the three main classifications of design patterns,
and categories of each that will be covered in
the course.
❶ Introduce the Creational design pattern
❷ Introduce the Structural design pattern
❸ Introduce the Behavioral design pattern
1.4 Advanced Python Topics
Explore some advanced inbuilt Python implementations of some
design patterns.
❶ Demonstrate how a Python iterator works
❷ Understand and explore examples of list comprehension
❸ Understand and explore examples of Python decorators
1.5 Inheritance in Python
Look at how single and multiple inheritance works in Python,
with an understanding of the differences between Python 2 and 3.
❶ Demonstrate single inheritance with overriding and
overloading
❷ Understand multiple inheritance and method resolution order
❸ Be aware of different inheritance syntax between Python
versions
Section 2: Producing with
Factories
2.1 Factory
Present the Factory pattern.
❶ Understand the intention of the Factory pattern
❷ Study diagram of the general implementation of the pattern
❸ Walk through a concrete implementation of the Factory pattern
2.2 Abstract Factory
Present the Abstract Factory pattern.
❶ Understand the intention of the Abstract Factory pattern
❷ Understand how it’s an extension of the Factory pattern
❸
Extend the previous example to demonstrate an Abstract Factory implementation
2.3 Builder
Present the Builder pattern.
❶ Understand the intention of the Builder pattern
❷ Study diagram of the general implementation of the pattern
❸ Walk through a concrete implementation of the Builder pattern
2.4 Prototype
Present the Prototype pattern.
❶ Understand the intention of the Prototype pattern
❷ Demonstrate how it can be used to avoid initialization costs
❸ Demonstrate how it can be used to copy and modify an instance
2.5 Singleton Versus Borg
Present the Singleton and Borg patterns.
❶ Understand and demonstrate the Singleton and Borg patterns
❷ Compare both patterns and discuss advantages and
disadvantages of each
❸ Show that Python modules are Singletons
Section 3: Structuring
Around
3.1 Model View Controller
Present the Model View Controller (MVC) pattern.
❶ Understand the intention of the MVC pattern
❷ Introduce Python web frameworks, Flask and Django
❸ Consider an example of MVC in Flask
3.2 Façade
Present the Façade pattern.
❶ Understand the intention of the Façade pattern
❷ Understand the benefits of the Façade pattern
❸ Apply the Façade pattern to the mechanics of starting a car
3.3 Proxy
Present the Proxy pattern.
❶ Understand the intention of the Proxy pattern
❷ Example of Proxy pattern using common interface with real
subject
❸ Example of generic proxy class which can be subclassed
3.4 Decorator
Present the Decorator pattern.
❶ Understand the intention of the Decorator pattern
❷ Show how it can be better than subclassing
❸ Example of using decorators to compose different UI windows
3.5 Adapter
Present the Adapter pattern.
❶ Understand the intention of the Adapter patter
❷ Explain when one might want to use the Adapter pattern
❸ An example of adapting a European socket to an American one
Section 4: Behaving
Ourselves
4.1 Command
Present the Command Pattern.
❶ Understand the intention of the Command pattern
❷ Demonstrate the general Command pattern implementation
❸ Look at an example of cut and paste from a screen of text
4.2 Interpreter
Present the Interpreter pattern.
❶ Understand the intention of the Interpreter pattern
❷ Demonstrate the general Interpreter pattern implementation
❸ Implement a simple rule validator using the Interpreter
pattern
4.3 State
Present the State pattern.
❶ Understand the intention of the State pattern
❷ Demonstrate the general State pattern implementation
❸ Apply the pattern to changing states of a computer
4.4 Chain of Responsibility
Present the Chain of Responsibility pattern.
❶ Understand the intention of the Chain of Responsibility
pattern
❷ Explain when it should and shouldn’t be used
❸ Example of a garage handling cars with different servicing requirements
Section 5: Behaving
Ourselves Again
5.1 Observer
Present the Observer pattern.
❶ Understand the intention of the Observer pattern
❷ Explain its relation with MVC
❸ Show an example of stock markets observing a company
5.2 Strategy
Present the Strategy pattern.
❶ Understand the intention of the Strategy pattern
❷ Program to an interface, not an implementation
❸ Use the strategy pattern to find prime numbers
5.3 Memento
Present the Memento pattern.
❶ Understand the intention of the Memento pattern
❷ Create an Undoable class using a Memento class
❸ Compare with the Command pattern to implement undo
5.4 Template
Present the Template pattern.
❶ Understand the intention of the Template pattern
❷ Understand how it’s used in frameworks
❸ Demonstrate an example of using a template to make different
meals
5.5 Reactive Programming
Present the concept of reactive programming and RxPY.
❶ Understand the intention of reactive programming
❷ Introduce RxPY - a set of Python libraries for reactive
programming
❸ Show how to install and start using RxPY
Section 6: No Pattern
(a.k.a AntiPattern)
6.1 Spaghetti Code
Present the spaghetti code AntiPattern.
❶ Understand why spaghetti code is an AntiPattern
❷ Understand common symptoms, consequences, and causes
❸ Demonstrate a spaghetti code example, explain how to improve
it
6.2 Blob
Present the blob AntiPattern.
❶ Understand why blob is an AntiPattern
❷ Understand symptoms and consequences of blob
❸ Demonstrate how to refactor away from a blob class
6.3 Functional Decomposition
Present the functional decomposition AntiPattern.
❶ Understand why functional decomposition is an OO AntiPattern
❷ Understand the symptoms and consequences of functional
decomposition
❸ Compare a functional decomposition versus an OO solution for
a problem
6.4 Copy and Paste
Present the Copy and Paste AntiPattern.
❶ Understand why Copy and Paste is an AntiPattern
❷ Understand symptoms and consequences of Copy and Paste
❸ Explore potential causes of Copy and Paste programming