码迷,mamicode.com
首页 > 其他好文 > 详细

Flyweight Design Pattern

时间:2019-07-31 13:31:53      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:foo   different   图片   man   col   mil   when   com   new   

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.

 

Flyweight Design Pattern

标签:foo   different   图片   man   col   mil   when   com   new   

原文地址:https://www.cnblogs.com/codingyangmao/p/11275399.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!