It is one of the structural design patterns that is used to reduce the number of objects created to improve the memory footprint of an application. It is usually employed whenever we have limited memory or we can reuse the already existing similar kind of objects. It also helps in improving performance.
Let’s take an example of an application where the Flyweight pattern can be applied to improve its memory footprint. Notepad++, A Text Editor which we want to implement. For simplicity, Assume we can write anything in the notepad++ using A-Z, a-z, and 0–9, space characters.
A Client writes a paragraph using the mentioned characters. The same character would be repeating a couple of times. Can we create an object for those characters just once in the first use and reuse the same object in future uses?