flyweight-pattern

Installation
SKILL.md

Flyweight Pattern

The flyweight pattern is a useful way to conserve memory when we're creating a large number of similar objects.

In our application, we want users to be able to add books. All books have a title, an author, and an isbn number! However, a library usually doesn't have just one copy of a book: it usually has multiple copies of the same book.

When to Use

  • Use this when creating a huge number of objects that could potentially drain available memory
  • This is helpful when many objects share the same intrinsic properties (e.g., books with the same ISBN)

When NOT to Use

  • When the number of objects is small enough that memory is not a concern
  • When objects have few or no shared intrinsic properties — the separation of intrinsic and extrinsic state adds complexity without savings
  • When the added lookup/management overhead outweighs the memory benefit

Instructions

Related skills
Installs
298
GitHub Stars
202
First Seen
Mar 30, 2026