The flyweight design pattern

Usually when software is written, developers try to make it fast and efficient. Normally, this means less processing cycles and a smaller memory footprint. There are different ways to achieve these two aspects. Most of the time, a good algorithm will take care of the first one. The amount of used memory can have many causes and solutions, and the flyweight design pattern is there to help and reduce the memory used.

Note

The purpose of this design pattern is to minimize the memory usage with the help of an object that shares as much data as possible with other similar objects.

There are many cases where many objects share the same information. A common example when talking about flyweight is word processing. Instead of ...

Get Scala Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.