[Tutor] who called the class method?

Alan G alan.gauld at freenet.co.uk
Wed Jun 22 00:49:14 CEST 2005


> Is there a way to test if a class method was called from an
instance?

I think you'll need to override the __getattr__ method.
It will pick up the call and you can test whether its a
class mrethod being called. I think...

> What I am trying to do is if a method is called from the
> class return a commanding proxy with an mock or stub type
> object as the proxied object. If it is called from the
> instance I want to return a proxy for the instance.

I'm not quite sure I understand because you are mixing object
oriented terminology with procedural programming terminology.

I think you mean you want to have a class with various methods.
You may or may not have instances of the class.
You want to know when a method is invoked whether this was via
a direct call of the class's method or via a message being
sent to an instance?

OR do you mean you will have an actual class method
(ie static in C++/Java speak) and want to know if the
activating message was sent to the class object or to
an instance of the class?

Or do you want to know if the class method was invoked
from within another method of the same class or invoked
by a message sent from an instance of another class?

Those are all different scenarios which could be described
by your paragraph above, which do you mean?
Or is it something different again?

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list