A flyweight (also sometimes called a token or a cookie) is a temporary component that acts as a “smart reference” to something. Typically, flyweights are used in situations where you have a very large number of very similar objects and you want to minimize the amount of memory that is dedicated to storing all those values.
Let’s take a look at some scenarios where this pattern becomes relevant.
User Names
Imagine a massively multiplayer online game. I bet you 1 bitcoin there’s more than one user called John ...