Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Do you like the interface, and is it simple enough to not be limiting?

Yes, that's a really clean implementation of this pattern, and in nicely idiomatic Perl.

Do you think people will use it?

That's hard to tell -- as Conway notes, this approach is underappreciated, and modules that make it easier may or may not push it over the tipping point of widespread acceptance... But it'd be nice if they did!

Something just doesn't feel comfortable about ... clone()

Looking at the code, what it does is store() some data and give you back the flyweight index. Calling it store() also fits in with fetch(), delete, and each(), all standard names for hash-like operators.

Where should I beef up/trim down/improve the documentation?

At times it's not immediately clear whether "the flyweight object" in the documentation is referring to the central Flyweight hash or to the individual objects; it might help to call them "the storage object" and "the index objects" or something like that.

It's probably worth noting in the "How do I use it?" section that in order to obtain the privacy benefits, the flyweight storage object should be held in a file lexical variable rather than a package variable.

The only part I was unclear about was the subclassing strategy -- if I'm using a Class::Flyweight to store private data for MyBank::Tx, with various subclasses like MyBank::Tx::Deposit, MyBank::Tx::LoanPmt, and so forth, is there some way to "stack on" the new accessors the subclasses will want to declare?

FWIW, that's the concern that drove me to adopt a one-hash-per-accessor approach in Class::MakeMethods::Template::Flyweight. As you noted in your posting, that module is still sketchy, and the data is not fully private. To be honest, I've basically been ignoring the encapulation angle, and using it more for the ability to add arbitrary data to existing objects, like reconnect attributes for a DBI handle, without messing around with the tied-hash internals...

Anyway, again -- nice module, and it's good to see more explicit discussion of software patterns and other highbrow engineering concepts in a Perl context.

In reply to Re: Class::Flyweight - implement the flyweight pattern in OO perl by simonm
in thread Class::Flyweight - implement the flyweight pattern in OO perl by dkubb

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

  • 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:
    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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (9)
    As of 2018-06-18 23:52 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (111 votes). Check out past polls.