My views on the flyweight Mode

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.