How to create an object without exposing the creation logic

Photo made with Canva.

The Factory Pattern is one of the core design pattern principles for creating an object. It allows clients to create objects using a common interface. In TypeScript, there are many different ways in which you can use the factory pattern to make your code cleaner and more concise. In this article, we’ll demonstrate how to create a factory pattern using TypeScript Generics.

What is Factory?

The authors of the book Design Patterns: Elements of Reusable Object-Oriented Software define the Factory Pattern as:

In other words, the factory…

Cesar William Alvarenga

Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store