ebooksgratis.com

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
Talk:Flyweight pattern - Wikipedia, the free encyclopedia

Talk:Flyweight pattern

From Wikipedia, the free encyclopedia

Flyweight is a software design pattern.

The sentence above is how the articles title "builder pattern", "adapter pattern", etc. should begin. Someone who is ignorant of computer software looking at those articles should be told right at the beginning that that is what the article is about. -- Mike Hardy


Chnged the method printAtPosition() to a static one as the point of a flyweight object was to save memory. -- Jari Mustonen


each GraphicChar takes 10 bytes of heap space (8 overhead + 2 char + 4 string pointer for font)

8 + 2 + 4 = 14, not 10 --195.6.224.137 15:17, 18 October 2006 (UTC)

I'm removing the two paragraphs that start "Often the desire to use a flyweight pattern indicates another design problem" because they seem way off-topic, they contain errors (see comment above regarding addition error), and they sound a lot like original research. CMosher01 17:16, 24 October 2006 (UTC)

As the author said that this is structural pattern, According to me its not structural or object oriented pattern, it's a hybrid pattern which consist both kind of pattern.--- Sanket Patel

[edit] Memory issue in the Java example

The Java example adds WeakReferences into the flyweightData map but at no point removes them. This could in time lead to a very large map, whose values would mostly end up being null-valued WeakReferences.

Actually it doesn't because the map used is a WeakHashMap and the keys are the same as the referenced value. This approach works nicely when object creation cost is low and the object itself can be used as the key.

When object creation is high and needs to be avoided as well as keeping memory usage down some sort of other key needs to be used. If the object's hashCode can be replicated with the same parameters given in the constructor then the hashCode is a good choice. But now you definitely have the problem of the map potentially growing large with null-valued WeakReferences. The solution is to attach a ReferenceQueue that removes the entry from the map.

org.apache.commons.collections.map.ReferenceMap provides a basic solution for this, but there exists a superior solution, also open sourced, here http://sesat.no/projects/sesat-commons/commons-reference-map/

> This implementation improves over org.apache.commons.collections.map.ReferenceMap > in that the synchronisation and concurrency is determined through delegation to the > map supplied in the constructor as described above.

Michaelsembwever (talk) 21:48, 20 March 2008 (UTC)

[edit] VB.Net example: Is this a flyweight?

I removed this section from the article:

[edit] VB.NET

' The "PersonFlyweight" is a "Person" stripped of all fields (to save memory) that 
' are not used in the immediate task at hand.  This is appropriate when loading millions of 
' objects into memory at once.
Class PersonFlyweight
   Public Sub New(p As Person)
      Me.FirstName = p.FirstName
      Me.LastName = p.LastName
   End Sub
 
   Public FirstName As String
   Public LastName As String
End Class
 
 
' "Person" entity with many fields.
Class Person
   Public FirstName As String
   Public LastName
   Public Address As String
   Public PreviousAddress As String
   Public PhoneNumberHome As String
   Public PhoneNumberWork As String
   Public PhoneNumberCell As String
   Public PhoneNumberFax As String
   Public Height As Double
   Public Weight As Double
End Class

To me it doesn't look like a Flyweight. It may be a pattern to save memory, but to me it doesn't look anything like the Flywight pattern. Am I wrong? --Teglsbo (talk) 12:50, 21 April 2008 (UTC)


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -