Chapter 21. Flyweight
Public transportation, such as buses, has been around for over a century. A lot of passengers can share the expenses of owning and operating vehicles (e.g., buses) when they all go in the same direction. There are multiple stops/stations in public transport. People just hop on and off along the route close to the place where they want to go. The expenses of getting to the place are limited to just the trip. Compared to the costs of owning a vehicle, taking public transport is a lot cheaper. That is the beauty of sharing common resources.
In object-oriented software design, sometimes sharing common objects not only saves resources but also increases performance. For instance, we need one million instances of a class for a particular ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access