Please look at Class::Object before responding.  URL below.


On Fri, Jun 29, 2001 at 06:36:31PM -0400, John Porter wrote:
> [EMAIL PROTECTED] wrote:
> > "Any sufficiently encapsulated hack is no longer a hack."
> 
> Who said that?  I think it's wrong.

Me.


> Any sufficiently encapsulated hack is no longer a *naked* hack.  So what.

As long as the hack has no effect outside its little bubble of
encapsulation, its no longer a hack as far as the outside world is
concerned.  Its a simple matter of interface perspective.


> > You shouldn't be relying on an object's reference.  ref $obj eq
> > 'Some::Class' wrecks subclassing, 
> 
> ref($a) eq ref($b).

That's generally bad.  Consider the following real world scenario:

        # Shop::Video represents a VHS, DVD or Laserdisc.
        $video = Shop::Video->new($video_id);

So is ref $video eq 'Shop::Video'?  Nope.  Shop::Video->new() is a
factory method.  It returns either a Shop::Video::VHS,
Shop::Video::DVD or Shop::Video::LD object depending on if the
$video_id refers to a VHS, DVD or Laserdisc.  Those are all
Shop::Video subclasses, so they all have the same interface.
The caller never has to know any of this.

Factory methods are a common design pattern.  There are other times
when you might have to rebless objects into subclasses unbeknownst to
the caller.  Adaptor and Proxy design patterns can be easily
implemented this way.

$a->isa($some_class) && $b->isa($some_class) is the correct way to see
if two objects have the same interface.


> > What's the trade-off here?  It works, its efficient, the hacks are
> > well encapsulated.
> 
> Having it in the core, in C[++], would be that much more efficient,
> and that much less of a hack.  Maybe the tradeoff is that it
> wouldn't work.  :-)

Everyone's making these assumptions, WHY WON'T ANYONE LOOK AT
CLASS::OBJECT?!

They're NO SLOWER than normal objects, it uses all the normal OO
channels, it was very simple and small to implement and it WORKS!
Now, right this second, with perl 5.

I'll post the URL yet again...
http://www.pobox.com/~schwern/src/Class-Object-0.01.tar.gz


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <[EMAIL PROTECTED]>       Kwalitee Is Job One
conway: unit of mind expansion.  One Conway == ~20 lines of Perl code
  found in $CPAN/authors/id/D/DC/DCONWAY, which gives the sensation
  of your brain being wrapped around a brick, with kiwi juice squeezed
  on top.
        -- Ziggy

Reply via email to