The Factory Method Design Pattern in Python

python_tutorials

Introduction

In this article, we’ll be diving into the Factory Method Design Pattern, implemented in Python.

Design Patterns define tried and tested solutions to various recurring problems in software development. They do not represent actual code, but rather ways in which we can organize our code for the optimum results.

In a world of limited resources, Design Patterns help us achieve the most results with the least amount of used resources. It is also important to note that Design Patterns do not apply to all situations and it is crucial to assess the problem at hand in order to choose the best approach for that particular scenario.

Design Patterns are divided into a few broad categories, though mainly into Creational Patterns, Structural Patterns, and Behavioral Patterns.

The Factory Method pattern is a Creational Design Pattern.

The Factory Method Design Pattern

Definition

The Factory Method is used in object-oriented programming as a means to provide factory interfaces for creating objects. These interfaces define the generic structure, but don’t initialize objects. The initialization is left to more specific subclasses.

The parent class/interface houses all the standard and generic behaviour that can be shared across subclasses of different types.

To finish reading, please visit source site