Today, I read the article flyweight of design patterns in Banqiao, and I found that my understanding is somewhat different.
The purpose of Flyweight is to reduce memory consumption. Therefore, it is a mode for solving implementation problems, rather than solving modeling problems.
In the example in this article, class CD is the flyweight interface, while class artist is concreteflyweight. That is completely wrong.
In the flyweight mode, flyweight and concreteflyweight are inherited.
In this article, it becomes an aggregation relationship.
In the flyweight mode, the most important thing is to break down the object into extrinsic and intrinsic parts.
In flyweight interface, it should be a context-related operation, but in the example, no context-related operation is visible.
The authors equate the flyweight mode with the object pool. But in fact, the two are essentially different. The object in the object pool does not have extrinsic, nor does it know the existence of context. For example, the most common string pool. The string in the pool can be used anywhere.
It is hoped that Mr. Banqiao will be able to modify the above in the spirit of being responsible to readers.
Above.