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 09:50
Subject:
Re: Class::FakeAttributes -- Opinions Wanted
Message ID:
20031102174907.GA1862@klangraum
* Smylers <Smylers@stripey.com> [2003-11-02 18:05]:
> However, even now I know the name for the technique I don't
> think it'd be appropriate to call the module
> Class::InsideOutAttributes (or similar), because that is
> describing the module's implementation rather than the
> situation in which it is useful.

How is "FakeAttributes" any less dependent on implementation? The
attributes aren't fake, they're actual subclass attributes, only
called "Fake" because they don't live in the $self hashref.

An actually implementation agnostic name would probably be
something like ::SafeInheritance. (Which it isn't completely
though, but see below.)

> Class::FakeAttributes helps in a different situation, where a
> class author is subclassing something that is based on, for
> example, a scalar ref but he/she wants to add instance data in
> the subclass.

Yes, Abigail invented inside out objects for two reasons - one of
them being to be able for a class to be completely superclass
implementation agnostic. Including choice of superclass $self
data type.

> The methods in this class are intended to help the subclass
> author access the attributes inside the class definition, not
> to provide public methods for use by the people creating
> objects of that class.

But that loses the other advantage of inside out objects: compile
time stricture checking. If you write

    $attribtue{$self}

(note the typo for $attribute), Perl will complain. If you write

    $self->get_attribute('attribtue')

that's a runtime error at most.  In your module, it isn't even
that much, because you don't ask the classes' author to declare
the attribute names so you can't check them.

In general I find the interface rather ill thought out; of
course, if it did the job for you, hey presto.

But I'd prefer to do

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

rather than

    for($self->attribute_list('foo')){ ... }

> But if the consensus of this list is that I should remove
> Class::FakeAttributes from Cpan then I shall do so.

So far it's one man's opinion; that hardly counts as consensus.

-- 
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