Simple Factory vs Factory Method vs Abstract Factory: A Practical Python Guide
A DEV Community article breaks down three creational design patterns — Simple Factory, Factory Method, and Abstract Factory — using a multi-database system as a practical example. The naive approach of letting individual services decide which database objects to instantiate violates the Single Responsibility and Open/Closed principles. Simple Factory centralises object creation but still requires modifying existing code whenever a new database type is added. Factory Method solves this by delegating object creation to each database subclass, eliminating conditional logic entirely. Abstract Factory extends this further by grouping related object families — such as queries, transactions, and updaters — under a single interface per database type.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in