Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re (tilly) 7: Tie & Destroy, OOP

by tilly (Archbishop)
on Aug 10, 2001 at 05:14 UTC ( [id://103730]=note: print w/replies, xml ) Need Help??


in reply to (tye)Re2: Tie & Destroy, OOP
in thread Tie & Destroy, OOP

Yes, you can do the same with a global variable. However my point was that even with every lexical in file scope, having one of the direct references to a lexical inside of a function brings the problem back.

BTW the more I think about it, the more I like the idea of having a flyweight implementation with an END block to kill all of the objects. That allows module authors to create objects which clean themselves up reliably without assuming that users are cautious.

Replies are listed 'Best First'.
(tye)Re3: Tie & Destroy, OOP
by tye (Sage) on Aug 10, 2001 at 06:26 UTC

    That (flyweight strategy) doesn't really solve the problem since you still end up destroying objects in a random order. It will help with multiple objects from the same module having a special order that is required (so long as you design your own way to keep track of this special order which may boil down to you reimplementing your own form of reference counting), but if you have two modules that reference each other in some general way, then using a END-based destructor is just as bad as Perl's global destruction problem (except that Perl's problem will be fixed soon).

            - tye (but my friends call me "Tye")
      You are right that when I think it through carefully there are plenty of cases where it doesn't work. But if you have objects in a class which are backed by available data that you want to get a chance to save to disk, well then protecting that class in a Flyweight pattern gives you an opportunity to allow the data to be saved correctly.

      I whipped up a proof of concept at Class::FlyweightWrapper. Take a look at how that works then look at the root node of this thread. I believe that if GMS::MemberFile was made into a wrapper around a private implementation through my new module, then DESTROY would work as desired. Sure, you can find situations where it would break, but it is at least a solution to the problem at hand.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-16 05:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found