...

/

Creational Patterns

Creational Patterns

Learn about different creational patterns, specifically factories, singleton, and builder patterns.

We'll cover the following...

Factories, the singleton pattern and the builder pattern are some of the most common creational design patterns.

Factories

The factory pattern provides an abstract class for defining objects in superclasses, while allowing subclasses to choose which class to instantiate. The subclasses are in charge of creating class instances.

Press + to interact

One of the core features of Python is that everything is an object, and as such, they can all be treated equally. This means that there are no special distinctions of things that we can or cannot do with classes, functions, or custom objects. They can all be passed by a parameter, assigned, and so on.

It is for this reason that many of the factory patterns are not usually needed. We could just simply define a function that will construct a set of objects, and we can even pass the class that we want to create with a parameter. ...