Muší váha

Muší váha, or „flyweight,“ is a design pattern in software engineering that is used to minimize memory use by sharing objects. It is particularly useful when a program needs to create a large number of instances of a class where most of them have the same data. In this pattern, the common data is stored in a central shared instance, allowing multiple objects to reference this shared instance instead of duplicating the data for each object. This reduces memory consumption and can improve performance, especially in scenarios involving many similar objects.

The Flyweight pattern typically involves creating a factory that manages the shared instances and provides them to the client code as needed. It separates intrinsic state (shared, immutable data) from extrinsic state (unique, contextual information required for operation), enabling efficient memory usage while maintaining the functionality of the objects. The Flyweight pattern is often utilized in graphics, games, and data-heavy applications where efficiency in resource management is critical.