Design Patterns with Python

This course will introduce you to eight classic software design patterns and how they can be implemented in Python to help you create programs that are professional, extendable, and maintainable.
Course info
Rating
(78)
Level
Intermediate
Updated
Oct 13, 2016
Duration
1h 57m
Table of contents
Course Overview
Introduction to Design Patterns
Design Patterns with Python
The Observer Pattern
The Command Pattern
The Singleton Pattern
The Builder Pattern
The Factory Pattern
The Abstract Factory Pattern
The Null Pattern
Course Summary
Description
Course info
Rating
(78)
Level
Intermediate
Updated
Oct 13, 2016
Duration
1h 57m
Description

At the core of professional programming practice is a thorough knowledge of software design patterns. In this course, Design Patterns with Python, you will learn eight classic patterns and how to implement them in Python. You will learn how to recognize problems that are solvable using design patterns, how to implement them professionally, and how they can be used to make your programs easier to write, easier to read, and easier to maintain. When you're finished with this course, you will have a better understanding of the elements of reusable object-oriented software design, which will help you as you move beyond simple scripts to complex systems built in Python. Software required: A Python interpreter in the 2.7 series or the 3.5 series and a Python-aware integrated development environment (IDE).

About the author
About the author

Gerald is a multiple-year of the Microsoft MVP award, Gerald has led introductory classes in Python and SQL for industry-sponsored events at Ryerson University, Toronto and the University of Toronto (his alma mater). 

More from the author
Getting Started with Python on SQL Server
Intermediate
1h 25m
18 Apr 2018
Functional Programming with Python
Advanced
1h 49m
2 Aug 2017
Building More Python Design Patterns
Intermediate
2h 7m
10 Apr 2017
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hi everyone. My name is Gerald Britton, and welcome to my course, Design Patterns with Python. In case you're curious, I'm a senior solutions designer at TD Bank in Toronto, Canada. In this course, we're going to learn about the elements of reusable object-oriented software design as presented in the classic Design Patterns book by Gamma, Helm, Johnson, and Vlissides, and how to write those patterns and use them in Python. This material will take an intermediate Python programmer to the next level and lay a foundation for moving beyond simple scripting to complex projects developing full-fledged, large scale applications. Some of the major topics we will cover include a review of object-oriented design principles and the convenient acronym to remember them by, SOLID. Eight design patterns used in many programming languages today. Common programming challenges made easier by using these patterns. Typical business problems and how to solve them using the patterns we look at. And also, several IDEs with excellent tools for developing and debugging Python projects. By the end of this course, you'll have learned how to apply design patterns to break down tricky problems into simple components and create Python programs that are easy to write, easy to read, and easy to maintain. Before beginning this course, you should be familiar with basic Python programming, including how to write classes, functions, and methods, and how to create and use modules and packages. I hope you'll join me on this journey to learn how to use classic design patterns in Python programs with the Design Patterns with Python course at Pluralsight.

Introduction to Design Patterns
Hello. Welcome to the course, Design Patterns with Python. My name is Gerald Britton, and it will be my pleasure and challenge to guide you through this study, which will start you on your way to creating more stable, maintainable, and understandable Python programs. In this introductory module, we want to answer some basic questions. What are design patterns? How were they discovered? Why do we need them? What sorts of problems do they help us solve? We'll also look at the basic classification scheme for design patterns so that we can better understand the roles and applicability of each pattern we look at. This is also a great time to review some foundational principals of object-oriented programming. This set of principles will be our guide as we apply design patterns to approve our work. We'll look at the five main principles known by their acronym, SOLID. We'll take a quick look at the tools you will need to complete this course and we'll finish this module by taking a look at some Python code to help us understand how interfaces are designed and used in Python.

Design Patterns with Python
Welcome back to the course, Design Patterns with Python. My name is Gerald Britton, and in this module we will be learning about one of the most used patterns, the Strategy pattern. The Strategy pattern is classified as a Behavioral pattern, so it is used to control the operation of some object. In this case, the pattern provides a way to take a family of algorithms, encapsulate each one, and make them interchangeable with each other. Since the algorithms form a family, they will normally operate with the same set of inputs and outputs, and this is often accomplished by passing in some common object as input, as we'll see shortly in our example. The algorithms are allowed to vary independently and their implementations can be quite different. Consider the differences between calculating gravitational attraction using Newton's formula as opposed to Einstein's general relativity. Very different, yet bot have the same inputs and outputs, and both should yield the same result, at least on Earth. Sometimes the Strategy pattern is called the Policy pattern, reflecting its use in applying some sort of policy to the behavior of a software system.

The Observer Pattern
Hello again, welcome back to the course, Design Patterns with Python. My name is Gerald Britton and in this module we will be learning about a pattern that is heavily used for event monitoring, the observer pattern, the observer pattern is a behavioral pattern, so it used to control the operation of some object, in this case, the pattern provides a way to define a one-to-many relationship between a set of objects, so that when the state of one object changes, all its dependent objects are notified. This pattern is also known as the dependents pattern or the publish-subscribe pattern, the last name yields a natural example, if you subscribe to a newspaper or magazine, whenever a new edition is published, you'll receive a copy in the mail. If that sounds a little old-fashioned, well, it's the same idea at work, when you subscribe to a Twitter feed or a YouTube channel or an email list or indeed any sort of push service.

The Command Pattern
Hello again, welcome back to the course, Design Patterns with Python. My name is Gerald Britton, and in this module, we will be learning about the Command Pattern, a pattern you'll find in toolkits, command-line programs, GUI menus, in fact, just about anywhere you want a simple way to corral diverse request processing objects into a common structure. As in other modules in this course, we'll be applying the principles of object-oriented programming, known by their acronym, SOLID. If you need a refresher, you can review the introductory module. The Command Pattern is a behavioral pattern, that means, it's used to control the operation of some object. In this case, the pattern provides a way to encapsulate a request as an object. This is in line with the principle, encapsulate what varies, and this encapsulation lets you parametrize various objects with different requests. The Command Pattern also provides a simple way to support queues and logs, perhaps for updating a database or creating an audit trail of requests. Using the Command Pattern, we can bacon support for undoable operations, and for macros, that is, sequences of commands. Sometimes, this pattern is also known as the Action Pattern or the Transaction Pattern.

The Singleton Pattern
Hello again. Welcome back to the course, Design Patterns with Python. My name is Gerald Britton, and in this module we'll be learning about the Singleton pattern, a pattern useful when you need to control access to class instances. As in other modules in this course, we'll apply the principles of object-oriented programming known by their acronym, SOLID. If you need a refresher, you can review the introductory module. The Singleton pattern is a Creational pattern, and that means it's used to create objects. In this case, just one object. Singleton can be used to ensure that a class has only one instance. This is handy when you need to control access to a limited resource such as a hardware device, a set of buffer pools, or perhaps connection pools for a web client or database access. Singleton also provides a global point of access for its one instance, and is responsible for creating that instance. But this is not always a good thing, as we'll see later. Singleton can also provide for lazy instantiation, which can be important if the object is costly to instantiate, or may not always be used.

The Builder Pattern
Hello again. Welcome back to the course, Design Patterns with Python. My name is Gerald Britton, and in this module we'll be learning about the Builder pattern, a pattern that can help with building complex objects. As in other modules in this course, we'll apply the principles of object-oriented programming, known by their acronym, SOLID. If you need a refresher, you can review the introductory module. The Builder pattern is a Creational pattern. That means it's used to create objects. Builder helps by separating the construction of a complex object, say an object representing a custom computer from its representation, what the specifications of the finished computer actually look like. Builder does this by encapsulating the construction of the object. Thereby obeying the principle, encapsulate what varies, which is a corollary of the single responsibility principle, the S in SOLID. It also allows for a multi-step construction process. In fact, this is where Builder really shines. Building a custom computer requires several steps, even when you're just looking at off-the-shelf components. One key benefit of the Builder pattern is that implementations can vary. Today I might want to build a powerful desktop workstation, tomorrow I might need a budget box. Builder can easily accommodate both without changing the client interface. The client sees only the abstraction.

The Factory Pattern
Hello again. Welcome back to the course, Design Patterns with Python. My name is Gerald Britton, and in this module we'll be learning about the Factory pattern, a pattern that is useful when we want to create different objects, but use one API to rule them all. As in other modules in this course, we'll apply the principles of object-oriented programming known by their acronym, SOLID. If you need a refresher, you can review the introductory module. The Factory pattern is a Creational pattern. In fact, the name itself implies just that. The Factory pattern defines an interface for creating an object, but it lets subclasses define which object to create. It does this through a factory method that lets a class defer instantiation to those subclasses. The Factory pattern is also known as the Virtual Constructor pattern.

The Abstract Factory Pattern
Hello again. Welcome back to the course, Design Patterns with Python. My name is Gerald Britton, and in this module we'll be learning about the Abstract Factory pattern, a pattern that is useful for creating families of related or dependent objects without specifying their concrete classes. As in other modules in this course, we'll apply the principles of object-oriented programming known by their acronym, SOLID. If you need a refresher, you can review the introductory module. The Abstract Factory pattern is a Creational pattern. It's a close cousin of the Factory pattern also covered in this course. Whereas Factory creates one product class, Abstract Factory can produce a family of classes and it enforces dependencies between the concrete classes. As with the Factory pattern, Abstract Factory defers object creation to concrete subclasses. The Abstract Factory pattern is also sometimes called the Kit pattern.

The Null Pattern
Hello again. Welcome back to the course, Design Patterns with Python. My name is Gerald Britton, and in this module we will be learning about the Null pattern. We've encountered this pattern a few times before, already in this course. In spite of its name, there really are a few things we need to talk about. Some call this a mini pattern, but that's because it is usually easy to implement with a few lines of code, not because it's unimportant. As is other modules in this course, we will apply the principles of object-oriented programming known by their acronym, SOLID. If you need a refresher, you can review the introductory module.