-
Book Overview & Buying
-
Table Of Contents
TypeScript 5 Design Patterns and Best Practices - Second Edition
By :
The last structural design pattern you’ll learn about in this chapter is the Flyweight pattern. The Flyweight pattern is a structural design pattern that optimizes memory usage of heavy objects – that is, objects that are very expensive to create and initialize. When we have to create lots of those objects, we might see lots of memory spikes, which could potentially affect parts of the system. In that case, we can use the Flyweight pattern to reduce the memory footprint by sharing or reusing functionality.
Environments such as game development, high-performance web applications, and large-scale data processing often require efficient memory management due to the frequent creation of numerous similar objects. In these contexts, the Flyweight pattern shines by allowing applications to share common data among many instances, significantly reducing memory consumption.
One analogy of this pattern is sharing a few traditional costumes among many...