Loading video player…

Implementing the Factory Method Pattern in Python (Overview)

This video course explores the Factory Method design pattern and its implementation in Python. Design patterns became a popular topic in late 90s after the so-called Gang of Four (GoF: Gamma, Helm, Johson, and Vlissides) published their book Design Patterns: Elements of Reusable Object-Oriented Software.

The book describes design patterns as a core design solution to reoccurring problems in software and classifies each design pattern into categories according to the nature of the problem. Each pattern is given a name, a problem description, a design solution, and an explanation of the consequences of using it.

The GoF book describes Factory Method as a creational design pattern. Creational design patterns are related to the creation of objects, and Factory Method is a design pattern that creates objects with a common interface.

This is a recurrent problem that makes Factory Method one of the most widely used design patterns, and it’s very important to understand it and know how apply it.

By the end of this video course, you will:

  • Understand the components of Factory Method
  • Recognize opportunities to use Factory Method in your applications
  • Learn to modify existing code and improve its design by using the pattern
  • Learn to identify opportunities where Factory Method is the appropriate design pattern
  • Choose an appropriate implementation of Factory Method
  • Know how to implement a reusable, general purpose solution of Factory Method
Download

Course Slides (.pdf)

4.0 MB
Download

Sample Code (.zip)

15.1 KB

00:00 Hello and welcome to this course on Implementing the Factory Method Pattern in Python. My name is Steven Loyens, and I will be your tutor for this course. The Factory Method design pattern is a way of structuring your code, and the code is structured such that there is a separation between the client code on the one hand, and on the other hand, the code that is needed to create the objects that the client will be using.

00:29 I like to think of it as the client ordering their products from a factory, instead of building them themselves.

00:36 Now, the Factory Method pattern is one of those things that once you understand it, you understand what it is and what it is doing, you start seeing it everywhere, and you’ll start seeing opportunities to use it everywhere.

00:48 So this will really change the way you code going forward. Now, what I’m particularly excited about is that this course doesn’t just talk about how to implement the Factory Method pattern, but it also talks about what it is actually trying to achieve and what it is. That is something that, in my opinion, is missing from most of the courses I have seen online.

01:13 So I’m quite happy to be offering you that today.

01:18 So what is it that you’ll be learning? Well, you’ll learn how to implement the components of the Factory Method pattern in Python. You’ll be hearing things about clients, factory methods, products, creators, and other interesting stuff.

01:33 You’ll also learn how to improve the design of existing code by applying the Factory Method pattern. So you’ll start from a basic example, and then gradually improve your code from a basic implementation to an advanced implementation of the Factory Method pattern.

01:52 And during this journey of code improvements, you will be implementing classes, data classes, abstract base classes and protocols, and you will be refactoring your code over and over again, making your code more robust while more flexible.

02:09 And finally, you will learn how to select an appropriate implementation of the Factory Method pattern for your code.

02:18 Now, there might be the odd occasion where you feel like, Steven, this implementation is potentially a little bit of overkill for the example that we’re working on.

02:28 And you would be right in thinking that. But remember that my intention is to show you a concept that is scalable, right? And with that I mean that it’s also useful for larger and more complex projects.

02:43 So these are the bits we’ll be going through, the introduction of the Factory Method pattern, of course, and as mentioned, then you will see basic implementation, and then move on to the advanced implementation.

02:56 There’s a lot of exciting content in this course, and I can’t wait to get going.

Become a Member to join the conversation.