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.