Flyweight in TypeScript
Flyweight is a Conceptual design pattern that allows programs to support vast quantities of objects by keeping their memory consumption low.
Pattern achieves it by sharing parts of object state between multiple objects. In other words, the Flyweight saves RAM by caching the same data used by different objects.
Learn more about Flyweight
Usage of the pattern in TypeScript
Usage examples: The Flyweight pattern has a single purpose: minimizing memory intake. If your program doesn’t struggle with a shortage of RAM, then you might just ignore this pattern for a while.
Identification: Flyweight can be recognized by a creational method that returns cached objects instead of creating new.
This example illustrates the structure of the Flyweight design pattern. It focuses on answering these questions:
- What classes does it consists of?
- What roles do these classes play?
- In what way the elements of the pattern are related?
index.ts: Conceptual Example
Output.txt: Execution result