Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Most of us are familiar with the term 'flyweight objects' in Perl OO speak, which refers to objects where the blessed thingy is a scalar that is the index into something (a hash or array) containing the object's attributes.

I happened to re-read the Flyweight pattern a few nights ago, and that description doesn't quite do the pattern justice. People often assume that "flyweight" means "small", since the point of the pattern is to separate intrinsic from extrinsic state such that objects that carry only intrinsic state (i.e., flyweights) can be shared multiple times. A common optimization is to have the flyweight hold an index into an attribute table, but important distinction is that attributes can't refer to state outside of the object itself if that reference would render the flyweight unsharable. Any non-shareable needs to be passed in by the client. A good test for whether you're really doing Flyweight right is to consider whether you can implement individual flyweight objects as singletons.

In reply to Re: Encapsulation through stringification - a variation on flyweight objects by dws
in thread Encapsulation through stringification - a variation on flyweight objects by robartes

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2021-06-22 11:05 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (104 votes). Check out past polls.