🎉 Hooray! After 3 years of work, I've finally released the ebook on design patterns! Check it out »

Flyweight in Swift

Flyweight is a Conceptual design pattern that allows programs to support vast quantities of objects by keeping their memory consumption low.

Pattern achieves it by sharing parts of object state between multiple objects. In other words, the Flyweight saves RAM by caching the same data used by different objects.

Learn more about Flyweight

Usage of the pattern in Swift



Usage examples: The Flyweight pattern has a single purpose: minimizing memory intake. If your program doesn’t struggle with a shortage of RAM, then you might just ignore this pattern for a while.

Identification: Flyweight can be recognized by a creational method that returns cached objects instead of creating new.

Flyweight in Other Languages

Flyweight in Java Flyweight in C# Flyweight in PHP Flyweight in Python Flyweight in Ruby Flyweight in TypeScript