Flyweight

Share immutable objects to save memory

Flyweight shares one copy of an object across many owners instead of duplicating it. Thousands of Dog instances each carry a breed โ€” but there are only ~200 breeds, and a breed is immutable. Interning them means every Golden Retriever points at the same Breed object.

The realization in Python is a factory with a cache dict: same key, same instance returned. Identity (is) proves the sharing.