O'Reilly logo

Mastering TypeScript by Nathan Rozentals

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Factory Design Pattern

To illustrate how we can use interfaces and classes in a large TypeScript project, we will have a quick look at a very well-known object-oriented design pattern—the Factory Design Pattern.

Business requirements

As an example, let's assume that our business analyst gives us the following requirements:

You are required to categorize people, given their date of birth, and indicate with a true or false flag whether they are of a legal age to sign a contract. A person is deemed to be an infant if they are less than 2 years old. Infants cannot sign contracts. A person is deemed to be a child if they are less than 18 years old. Children cannot sign contracts either. A person is deemed to be an adult if they are more than 18 years ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required