0 votes
in JAVA by
When do you use Flyweight pattern?

1 Answer

0 votes
by
This is another popular question from the design pattern. Many Java developers with 4 to 6 years of experience know the definition but failed to give any concrete example. Since many of you might not have used this pattern, it's better to look examples from JDK. You are more likely have used them before and they are easy to remember as well. Now let's see the answer.

Flyweight pattern allows you to share object to support large numbers without actually creating too many objects. In order to use Flyweight pattern, you need to make your object Immutable so that they can be safely shared. String pool and pool of Integer and Long object in JDK are good examples of Flyweight pattern.

Related questions

+1 vote
asked Apr 15, 2021 in JAVA by SakshiSharma
+1 vote
asked Jan 27, 2020 in JAVA by rahuljain1
...