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

Flyweight in PHP

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

The 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.

Usage of the pattern in PHP

Complexity:

Popularity:

Usage examples: The Flyweight pattern is especially rarely used in PHP applications due to the very nature of the language. A PHP script typically works with a part of the application’s data and never loads all of it into the memory at the same time.

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

Flyweight in Other Languages

Design Patterns: Flyweight in Java Design Patterns: Flyweight in C# Design Patterns: Flyweight in C++ Design Patterns: Flyweight in Python Design Patterns: Flyweight in Ruby Design Patterns: Flyweight in Swift Design Patterns: Flyweight in TypeScript Design Patterns: Flyweight in Go