develooper Front page | perl.module-authors | Postings from November 2003

Re: Class::FakeAttributes -- Opinions Wanted

Thread Previous | Thread Next
From:
A. Pagaltzis
Date:
November 2, 2003 16:12
Subject:
Re: Class::FakeAttributes -- Opinions Wanted
Message ID:
20031103001111.GA12649@klangraum
* Smylers <Smylers@stripey.com> [2003-11-03 00:40]:
> > An actually implementation agnostic name would probably be
> > something like ::SafeInheritance. (Which it isn't completely
> > though, but see below.)
> 
> Possibly.  But safety isn't really the point --
> Wx::StaticBoxSizer can safely be inherited from,

Well, you can't safely store your own attributes in a $self
hashref provided by a superclass; putting them in an out-of-band
data structure lets you.

Maybe that's the name you're after - Class::OutOfBandAttributes.

> That's a good reason; that would be a reason for all Perl
> objects doing all of their attributes like that (well, except
> when subclasses want to access their parents data ...).

Then the subclasses should use accessors. Just like you do in any
modern OO-aware language.

> My module is not intended to be a general implementation for
> people who want inside-out objects!  Anybody wanting such a
> module will be disappointed by trying to use my module!

Indeed, as I noticed by looking at it again, it does things quite
differently. The similarity is in using $self as a hash key.

> > But I'd prefer to do
> > 
> >     for(@{$self->get_attr('foo')}){ ... }          # A
> > 
> > rather than
> > 
> >     for($self->attribute_list('foo')){ ... }       # B
> 
> Believe it or not, so would I!  Because, in a 'normal' class I'd just
> write:
> 
>   foreach (@{$self->{foo}}) { ... }                  # C
> 
> so merely using $self->get_attribute('foo') in place of
> $self->{foo} would seem like the most natural alternative.
> And that's what I did first.
> 
> The only flaw with that approach is that it doesn't work!

You could just have people pass a default to get_attribute.

    for(@{$self->get_attr('foo', [])}){ ... }

If exists() shakes its head, that's what they get.

Or maybe you want to make this a distinct get_attr_or_default().

> It isn't that I don't consider Y to be a valid problem to
> solve, nor even that I'm against the existence of a module that
> solves Y.  It's just that it isn't this module.

It was mostly a misunderstanding. I didn't take a close enough
look at your code to see the difference before shooting off about
inside out objects.

Still, I don't consider it meritorious on the premise that it
isn't inside out, simply because if there was Class::InsideOut
and an someone installed it, they'd never need your module
again..  it's a pity there's nothing like it there yet because it
address 90% of the contemporary criticism of Perl-OO..

I guess in the absence of Class::InsideOut, having
Class::OutOfBandAttributes as a band-aid isn't a bad idea.
(There's a lot of orders of magnitude less useful stuff out on
CPAN..)

... Although.. just riffraffing about it on this thread gave me
enough sparks that I may well soon enough tackle the task.. :-) I
just need to bring all pieces of the puzzle that occured to me
together.

-- 
Regards,
Aristotle
 
"If you can't laugh at yourself, you don't take life seriously enough."

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About