Summary
The Flyweight pattern lets you share access to objects such as characters, chemicals, and borders, which may appear in large quantities. The flyweight objects must be immutable, a feature that you can establish by extracting the immutable part of the class you want to share. To ensure that your flyweight objects are shared, you can provide a factory where clients can find flyweights, and you have to enforce the use of this factory. Access modifiers give you some control over how other developers access your code, but nested classes take this control further, letting you guarantee that a class is accessible by only its containing class. By ensuring that clients use your flyweight factory properly, you can provide safe, shared access to what would otherwise be a multitude of fine-grained objects.