I've studiously avoided the term "flyweight objects" as I have only ever seen it here and didn't really understand its meaning. I'll stick to "Inside-out" which only has meaning in perl terms as far as I am aware.
Fair enough, but other people have - which makes me suspect it means something different in the perl and design pattern worlds.
Which would be annoying. One of the main advantages of the design pattern movement for me is the development of a common vocabularly (finally, everybody knows what a singleton is :-). If it means something different in the perl world it would be useful to know.
With regard to the example you describe, that may have made some sense in the world of 8-bit chars as you only need a pool of 256 object, but in the world of UCS, it becomes excessive I think...
I don't really want to repeat everything in the chapter from the book, but basically...
- The context is a word processor, so "character" doesn't just mean the code, it might support methods like draw(), intersects(), etc. We're talking WYSIWYG layout support.
- I didn't mean to imply you had to create the whole pool of characters at once, you would create them as needed for a document and add them to the pool.
As for practicality, the example was in the book was adapted from the Doc editor, produced using InterViews 3.0. Take a look at:
- Paul R. Calder and Mark A Linton. Glyphs: Flyweight bjects for user interfaces. In ACM User Interface Software Technologies Conference, pages 92-101, Snowbird, UT, October 1990.
- Paul R. Calder and Mark A Linton. The object-oriented implementation of a document editor. In Object-Oriented Programming Systems, Languages and Applications Conference Proceedings, pages 154-165m Vancouver, British Columbia, Canada, October 1992. ACM Press.
To quote from the Design Patterns chapter on flyweights:
Doc uses glyph objects to represent each character in the document. The editor builds one Glyph instance for each character in a particular style (which defines its graphical attributes); hence a character's intrinsic state consists of the character code and its style information (an index into a style table). This means only position is extrinsic making Doc fast.
If you're interested in the details I'd recommend picking up a copy of Design Patterns and giving the flyweight chapter a read.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||