Image for Flyweight

Flyweight

The Flyweight pattern is a software design approach that helps optimize memory usage by sharing common parts of objects instead of creating many separate instances. Imagine a game with thousands of trees; instead of creating a unique tree object for each, the program shares the same basic tree model, storing only the differences (like location or size). This way, many objects are lightweight, improving performance and memory efficiency. It’s useful when many objects share similar characteristics, allowing a system to manage large numbers of objects more effectively without consuming excessive resources.