SPUG: OO Perl object backrefrence question
Peter Darley
pdarley at kinesis-cem.com
Fri Sep 6 10:37:13 CDT 2002
Umar,
In this case I'm not inheriting, I'm using objects to hold info on it's
self, as well as collections of other objects that make up a hierarchy. So,
the page class isn't an inherited class of the survey class, the page
objects are just included in a property of the survey object. There might
be a structure like:
[My::Survey=HASH(0x80f6459)] = {ClientName => 'The Client',
Pages[1] => [My::Page=HASH(0x80f6460)]
Pages[2] => [My::Page=HASH(0x80f6461)]}
So, what I would like to be able to do is in the My::Page package be able
to do something like $Self->Parent->{'ClientName'} and get back 'The
Client'.
I don't know if that makes any sence or not...
Thanks,
Peter Darley
-----Original Message-----
From: Umar Cheema [mailto:umar at drizzle.com]
Sent: Friday, September 06, 2002 8:00 AM
To: Peter Darley
Subject: Re: SPUG: OO Perl object backrefrence question
Hmmm. Maybe I am not understanding it correctly but if you're inheriting
from the parent object wouldn't you be able to accomplish that by calling
a method like
$self->setClientName($client_name);
from the page object and having the setClientName method placed in the
parent object.
Then you can simply call a getter method like $self->getClientName() which
will simply return the client name from the parent object that you have
already set by calling setClientName from the page object?
On Fri, 6 Sep 2002, Peter Darley wrote:
> Friends,
> Another stupid question...
>
> I'm working on building a series of objects in a hierarchy that
represents
> a survey. The survey object will hold page objects which will hold
> questions object, etc.
> I'm wondering if there is a standard way for an object to know what it's
> parent object is so I can pull properties from the parent instead of
storing
> it in each child object. So, I want to be able to do something like
> $self->Parent->ClientName to get the client name of the survey a page
object
> is part of.
> There are two ways that I can see of doing this, but they're both not
> great. The first would be to give the child a reference to the parent
> object to store in a parent property, but this has problems with circular
> references, and I'd probably have to do my own garbage collection.
> The other is to pass a string containing the name of the variable
> containing the parent object (i.e. "$Main::MySurvey") then use "no strict
> 'refs'; $$Parent->whatever()" to de-reference it when it needs to be used.
> This would keep garbage collection working, but wouldn't, I believe, be
> storable, because the name would likely be different next time the script
is
> executed.
> Anyway, I was hoping that in addition to the normal messages letting me
> know that this is all a bad thing to do someone might have some advise on
> setting my objects up like this. :)
>
> Thanks,
> Peter Darley
>
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
> Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
> Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
> For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
> Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list
mailing list