Flyweight-C-

Flyweight pattern concepts

  • Intrinsic state: Allows you to share unchanging data between objects
  • Extrinsic state: Object-specific data can be passed in
  • Shared objects act as a kind of accessible & unchanging model, which can be reused as much as needed
  • Significantly cuts down on storage & memory usage
  • It requires a specialised scenario to be effective: When a large number of objects needs to be created & most object state is categorised as extrinsic, flyweight can be very effective (.e.g. in an application that has numerous menu items which might be ordered thousands of times in quick succession)

Example: Drinks Ordering App