On Thu, Jul 19, 2001 at 11:50:09PM +0100, Mark Maunder wrote:
> Sorry, just read the rest of your message.
> 
> Sortof. Grandfather has some utility methods in it that Son and Father both
> use. Son calls a method (call it save() )which it has defined. Within this
> method it uses one of the utility methods (lets call it
> Grandfather::get_name() ) defined within grandfather. Once Son::save() has
> finished doing its own stuff, it calls $self->SUPER::save() to call
> Father::save(). Father::save() also uses the same utility method defined
> within Grandfather i.e. Grandfather::get_name().
> 
> Now the problem is that  Grandfather::get_name() calls
> $self->_list_attributes() and expects that method to call _list_attributes()
> within the caller of Grandfather::get_name(). i.e. when Father::save() calls
> Grandfather::get_name() and Grandfather::get_name calls
> $self->_list_attributes() it expects Father::_list_attributes to be called.
> This is not the case because the original calling object is of type Son i.e.
> ref($self) within Grandfather::get_name returns 'Son'.

Ok, I think I understand now.


> Therefore the only was for Father::save() to call Grandfather::get_name is
> by doing:
> __PACKAGE__->get_name()
> which will then give Grandfather::get_name an object of type Father an which
> in turn will allow Grandfather::get_name to access
> Father::_list_attributes()

You keep calling __PACKAGE__ an object.  It's not.  By saying
__PACKAGE__->get_name() you are calling the class method Father::get_name().


> I dont think that this is an abnormal thing to do. I'm pretty sure that
> classes up and down a class heirarchy normally access methods from a
> 'senior' class (after being called from a 'junior' class) that in turn
> expect to be able to access data (via a data access method) in the calling
> class.

This is the first I've seen a use of this type of thing.  Typically, you
want to access a method in the object's class, in a parent class, or
possibly in the current class.


> Perhaps I should just stick to the standard paradigm of passing $self as it
> was received from 'my $self = shift @_;' to any called methods by doing a
> $self->methodname(), and instead use the caller() function in the method
> that exists in the class close to the top of the heirarchy (i.e.
> Grandfather::get_name() in the above example) to access data in the caller.

If caller() works for you, I suppose.  What is this intended to accomplish? 
Why does Father have a _list_attributes() that Grandfather needs access to? 
It almost seems like you're trying to control the attributes of your object
with methods; there are better solutions to that type of thing.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to