Reputation: 197
I understand the benefits of the flyweight design pattern, but I am unsure of its exact drawback. For example, I understand that it may be break encapsulation, but that is all I can currently think of, what are some possible drawbacks of the flyweight design pattern, there is very little documentation, on this matter.
Upvotes: 0
Views: 717
Reputation: 17144
On page 199, the GoF mentions,
Flyweights may introduce run-time costs associated with transferring, finding, and/or computing extrinsic state, especially if it was formerly stored as intrinsic state.
Flyweights can be a trade-off of space for time, if extrinsic state is computed or queried rather than stored. And of course there is some added complexity inherent to the pattern itself: data that was previously owned by each object and accessed directly must now be retrieved through some type of Factory, which adds an additional layer of indirection.
The narrow applicability of the Flyweight pattern could be considered a disadvantage as well. Five separate conditions must be met to take advantage of the pattern's benefits according to the GoF. This is the reason I believe Java's String.intern()
is not a Flyweight.
Upvotes: 0