Factory Pattern in TypeScript

When developing code, you may instantiate objects directly in methods or in classes. While this is quite normal, you may want to add an extra abstraction between the creation of the object and where it is used in your project.

You can use the Factory pattern to add that extra abstraction. The Factory pattern is one of the easiest patterns to understand and implement.

Adding an extra abstraction will also allow you to dynamically choose classes to instantiate based on some kind of logic.




A Design Pattern is a description or template that can be repeatedly applied to a commonly recurring problem in software design. A familiarity of Design Patterns is very useful when planning, discussing, managing and documenting your applications from now on and into the future.

Recommended from Medium

JavaScript SEO: How it Works

Create Random Particle Effects with Canvas

Update Your Salesforce Records using JavaScript Button

Getting started with Hapi 17

Things need to know every novice REACT developer.

Separating unit and integration tests in Jest

Can i tell a story in french. or can you translate a story in frenche

Understanding Streams By Implementing Your Own Pt 2

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
Sean Bradley

Sean Bradley

Developer of real time, low latency, high availability, asynchronous, multi threaded, remotely managed, fully automated and monitored solutions.

More from Medium

Bridge Pattern in TypeScript

Brief Intro to TypeScript Generics

Complete Dive Into TypeScript — Part 2

All You Need to Know about Environment Variables in TypeScript