Flyweight Pattern in Php — StudySection Blog

Useful note, before proceeding

What is the flyweight pattern?

When to Use the Flyweight Pattern

  • Flyweight objects should never be created by the client using the new keyword. Instances should always be created using factory class.
  • The factory class should store instances of each flyweight, similar to how a multiton stores a reference to an object in a static attribute.
  • Flyweight attributes that are not shareable (external) between all instances of Flyweight must be supplied by the client and stored inside the Flyweight object.
  • Flyweight attributes that are shareable (intrinsic) must be immutable and set by default to flyweight.
  • The client/controller is responsible for creating the flyweights using the factory class and providing them with the domain model.



The most loved online platform for eCertification in several subjects including but not limited to Software Development, Aptitude and more.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store