in reply to AbstractClassFactory

Like any piece of art the trick it knowing when to stop. You went one step too far here. Your code reference should not be blessed and the incant method is completely superfluous. I'd normally prefer to write that sort of thing as $obj -> ( 'method', @args ) since that's really what is happening anyway. The only thing you lose is the blessing's inheritance tree but you didn't mention that so I'm not sure if you even intended to use it. Personally I'm looking at your implementation as a way of getting to classless objects. All you really need here is the code reference - you just call it with the method/property name as a parameter to the object.


Also, some comments on style:

 $class = ref($class) || $class;

How about quiting the cargo cult line? For your concept it really doesn't fit here.

for (keys %$props) { $props->{$_} = $colors{$_}; }

Better done as a hash slice - your existing form is much less readable than it could be. Clearer: @{$props}{ keys %$props } = @colors{ keys %$props }

Replies are listed 'Best First'.
Re: Re: AbstractClassFactory
by hypochrismutreefuzz (Scribe) on Jan 14, 2003 at 01:46 UTC

    I am still trying to find a use for a closure that is used as an object reference. I guess that like any form of recursion its more effecient to "flatten" it out.

    Thanks for the comments; but what is a "cargo cult line"?

      You put the code $class = ref($class) || $class into your module. There's no good reason for you to do that. People here go on endlessly about this specific meme but in your particular case it is particularly extraneous. The only possible reason you would have for it in this example is for cargo cult reasons. See cargo cult programming. It should merely be left as my $class = shift without the "maybe clone this object but not really" meaning you're getting. Part of my original objection was that you didn't even need the blessing for what you were doing and this part I'm quibbling over muddies the waters even more.

      The other thing you're missing is that there is a universe of uses for closures and that isn't about "trying to find a use". If you really want to give your mind a spin go read up on Capabilities and faceted objects over at E in a Walnut. You'll come out better for it (it's only 70 pages and if you feel like it most of the middle can be skipped).


      Fun Fun Fun in the Fluffy Chair