加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Flyweight Design Pattern

发布时间:2020-12-15 05:32:21 所属栏目:Java 来源:网络整理
导读:Flyweight pattern is primarily used to reduce the number of objects created decrease memory footprint increase performance. Flyweight pattern tries to reuse already existing similar kind objects by storing them and creates new object when

Flyweight pattern is primarily used to

  • reduce the number of objects created
  • decrease memory footprint
  • increase performance.

Flyweight pattern tries to reuse already existing similar kind objects by storing them and creates new object when no matching object is found.

This type of design pattern comes under structural pattern.?

?

Below is an example with diagram and code as further explanation.?

Diagram

?

Code Explanation.?

We will demonstrate this pattern by drawing 20 circles of different locations but we will create only 5 objects.

Only 5 colors are available so color property is used to check already existing Circle objects.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读