Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^7: Flyweights - different meaning in perl?

by diotalevi (Canon)
on Dec 16, 2002 at 17:19 UTC ( #220278=note: print w/ replies, xml ) Need Help??


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

So:

  • The number of objects stays the same
  • The state stored by each object stays within it's class
  • The state stored by each object remains the same. It's just stored in the class, rather than within the object.
  • The method is used to implement data-hiding

Note we are not removing any duplicate state. We are moving state from the object to that objects class.

The motivation for doing it is data-hiding, not reducing duplicate state.

Actually I think it is very clear that the motivation is reducing the number of objects. I suppose data hiding might be a benefit but in general I don't respect data-hiding efforts in perl as valid activities. The idea is that instead of having one hash per object you now have a few larger structures per class but each object is only required to be a scalar.

I look at that and see Flyweight being applied to the perl structures. It's reducing redundant structures and in the process requiring less memory. It appears the typical application of FlyWeight (outside of Perl circles) is agnostic on language internals and intends to apply it to data and reduce memory load that way. This inside-out approach allows for a miminalist approach where you've got a few large arrays and a lot of small scalars instead of the more "normal" perl approach which simply has a lot of hashes. The assumption is that there is a higher memory overhead on having many hashes instead of few large arrays+many scalars.


Fun Fun Fun in the Fluffy Chair


Comment on Re^7: Flyweights - different meaning in perl?
Re^8: Flyweights - different meaning in perl?
by adrianh (Chancellor) on Dec 16, 2002 at 18:33 UTC

    Absolutely last comment :-)

    Actually I think it is very clear that the motivation is reducing the number of objects. I suppose data hiding might be a benefit but in general I don't respect data-hiding efforts in perl as valid activities. The idea is that instead of having one hash per object you now have a few larger structures per class but each object is only required to be a scalar.

    TheDamian's method implements a particular representation of objects in perl data structures. The number of objects (be they hashes or blessed scalars) stays the same. The amount of state (be it in a per-object hash or in a class-local array) stays the same.

    The flyweight pattern (in the DP world) is about making decisions about what state is stored where, and choosing a set of classes and objects that reduces the total number of objects in existence. It's a design decision (that's why they're called design patterns).

    You're right that TheDamian's method can be a more memory efficient way of implementing objects - but it doesn't affect the design of the object hierarchy. It's an implementation choice. Abigail-II's inside-out objects also save memory, but it doesn't make them a flyweight pattern.

    I'll shut up now :-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-09-21 10:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (168 votes), past polls