pub fn flyweight_exercise() -> Result<(), String>
Expand description

Example of using the “Flyweight” design pattern.

The Flyweight pattern is used when a large object needs to be represented by a much lighter weight struct, possibly multiple instances of said light-weight struct.

In this example, a large object is represented by a so-called “big resource” (a two-dimensional array of text characters) containing multiple images, one associated with each flyweight struct. FlyweightImage structs that represent an offset into the big resource, along with position and velocity, are attached to the big resource image so they all share the same image but have different positions and velocities. The image is rendered to a display area using the FlyweightImage struct. The FlyweightImage struct instances then have their positions updated, bouncing off the edges of the display area 60 times a second. This continues for 1000 iterations or until a key is pressed.