[Tutor] who called the class method?

David Driver count0.djd at gmail.com
Wed Jun 22 02:23:44 CEST 2005


You are right to be confused because I was as well. I was shooting for:

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

The easiest solution was to do a class method 'GetDefaultProxy' that
creates the default object (a stub with initial values) and creates
the proxy with it and an instance method 'GetInstanceProxy' that
creates the proxy for the already instanced object.

I am working on integrating sqlobject with formencode's validators and
a commanding proxy. Partly as an academic exercise. It is the biggest
OO project that I have ever tried in any language and it has turned
out to be pretty neat. There are a few details to work out but in the
end I think that I will have something special.

On 6/21/05, Alan G <alan.gauld at freenet.co.uk> wrote:
> 
> > 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
> 
> 


-- 

***********************************
See there, that wasn't so bad.
***********************************


More information about the Tutor mailing list