Reader small image

You're reading from  TypeScript 4 Design Patterns and Best Practices

Product typeBook
Published inSep 2021
Reading LevelIntermediate
PublisherPackt
ISBN-139781800563421
Edition1st Edition
Right arrow
Author (1)
 Theofanis Despoudis
Theofanis Despoudis
author image
Theofanis Despoudis

Theo Despoudis lives in Ireland, where he works as a Software Engineer for WP Engine and as a part-time tech practitioner for Fixate. He is the co-author of The React Workshop and Advanced Go Programming in 7 Days, Dzone Core Member, and maintains some open source projects on GitHub. Theo is available for conference talks, independent consulting, and corporate training services opportunities.
Read more about Theofanis Despoudis

Right arrow

Combining patterns

It's perfectly fine to combine design patterns as long as they do not interfere with one another or to eliminate any concerns. Doing so, you gain the benefits of both patterns while removing the need to write extraneous and sparse code that you may have when you create many abstractions.

We will showcase some examples of valid combinations of design patterns together with their usage.

Singleton

Singleton is the most flexible pattern to glue on. This is because the traits and benefits it offers usually do not interfere with other patterns and their responsibilities. Quite often, this pattern is implemented using TypeScript decorator syntax or by simply inheriting from the Singleton class.

We will discuss some of the most common patterns that pair well with Singleton:

  • Builder: The Builder object is usually a single instance and should only be used for creating a new object. However, before each use, the client should reset the Builder object...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
TypeScript 4 Design Patterns and Best Practices
Published in: Sep 2021Publisher: PacktISBN-13: 9781800563421

Author (1)

author image
Theofanis Despoudis

Theo Despoudis lives in Ireland, where he works as a Software Engineer for WP Engine and as a part-time tech practitioner for Fixate. He is the co-author of The React Workshop and Advanced Go Programming in 7 Days, Dzone Core Member, and maintains some open source projects on GitHub. Theo is available for conference talks, independent consulting, and corporate training services opportunities.
Read more about Theofanis Despoudis