Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Re: Flyweights - different meaning in perl?

by BrowserUk (Pope)
on Dec 15, 2002 at 18:33 UTC ( #220034=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Flyweights - different meaning in perl?
in thread Yet Another Perl Object Model (Inside Out Objects)

If you'd talked about Gylph objects instead of 'character' objects, I wouldn't have had to sit here and get all confused and indignant:)

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.

Ah! They mean Fonts! How original.


Examine what is said, not who speaks.


Comment on Re: Re: Re: Flyweights - different meaning in perl?
Re^4: Flyweights - different meaning in perl?
by Aristotle (Chancellor) on Dec 16, 2002 at 00:52 UTC
    I do think you got lost in the specifics of the example and failed to see the forest for the trees there. The point, as far as I understood, was that when you have to handle a huge number of tiny objects of the same (ancestral) class, whatever they may represent, and you can split the intrinsic and extrinsic states, then you do so and create a pool of object instances to refer to for the representation of a particular "thing"'s intrinsic state. That's a "flyweight object" - a class that contains only intrinsic state in order for its instances to be usable in multitude.

    Makeshifts last the longest.

      Update: Having found and read this description of Flyweight objects, I noticed first that the equipment being used was a DECstation 3100 (a machine I well remember playing "moonlander" on 16 or more years ago. It was "state-of-the art then and wowed everyone that saw it) and then noticed that the dates on the paper and the references therein were 1987,1988 & 1989. I then realised that this description of flyweight objects comes from a time when it may well have been considered unusual and new, though I don't recall them having a great impact at the time.

      Prior to this I was under the impression that "flyweight objects" were being hailed as something new and different, and was intrigued to learned more, but was confused by what I read. Effectively the referenced paper puts that idea to bed and makes the rest of this post redundant.

      I'll leave it here as is the apparent preference of the community as testimony that just because you haven't encountered the name of something, that you haven't been unwittingly using it for years. I guess what goes around comes around:^)

      End update

      Getting by the fact that I was arguing against the example given rather than the definition itself.

      Can you explain to me how an object can have extrinsic state?

      Using the Glyph example. The text given said that Doc was fast because it used Glyphs, which had no extrinsic state. The example give for what they did not have was position. If you add the position at which a Glyph is displayed or formatted to the Glyph itself, then you do indeed need many more instances than you would without it.

      However, if you add the position information to the Glyph class it then becomes intrinsic? But what you now have is no longer a Glyph class, but a Glyph_At_This_Position class. To my way of thinking that just doesn't make sense.

      You have a list (small-l) of Positions at which to display Glyphs, and you give the Glyph to the Position not vice-versa. That way, when you reformat to a different page width, you run down the list of Posistions and adjust them and the Glyphs move appropriately. If that means I'm wanting to use Flyweight objects for my Glyphs, then so be it, but it seems like a strange name for the concept and hardly new.

      I mean, we build strings from chars, we don't tell a char that it occupies position 7 in this string?



      Examine what is said, not who speaks.

        I'll leave it here as is the apparent preference of the community as testimony that just because you haven't encountered the name of something, that you haven't been unwittingly using it for years.

        That's what I think is the great thing about design patterns. They give names to all those things that we've been doing for years. This makes it a lot easier to talk about the concepts in question.

        By definition, a design pattern cannot be new. It has to have been done several times before people can spot it as a pattern :-)

        Getting by the fact that I was arguing against the example given rather than the definition itself.

        Apologies for the confusion caused by my poor nomenclature.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://220034]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-12-28 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls