AOP and metaclasses

S

Santiago Aguiar

Im trying to use AOP techniques on python but, even if I understand
the idea behind metaclasses, I cant find a way to use AOP in a dynamic
way.

What im trying to do is to weave an aspect to a class at runtime, but
i don't want to include any special code or definition in the class
itself. Also, i want to do
it just for some particular classes. Is there any way to do this?

I know its possible to apply an aspect to all the classes by
redefining __metaclass__, and that I can do the same with a single
class by assigning to __metaclass__ inside the class definition.
However, I want to avoid the last step, so i can apply the aspect to
any class.

thanks!!

saludos! santiago.
 
S

Shalabh Chaturvedi

Santiago said:
I know its possible to apply an aspect to all the classes by
redefining __metaclass__, and that I can do the same with a single
class by assigning to __metaclass__ inside the class definition.
However, I want to avoid the last step, so i can apply the aspect to
any class.

If one class has a __metaclass__ inside its definition, its subclasses will
use the same metaclass (unless they have another __metaclass__ in their
defintion). So you could define one class and use it as a base for the
specific classes that you want to affect.
 
J

John Roth

Santiago Aguiar said:
Im trying to use AOP techniques on python but, even if I understand
the idea behind metaclasses, I cant find a way to use AOP in a dynamic
way.

What im trying to do is to weave an aspect to a class at runtime, but
i don't want to include any special code or definition in the class
itself. Also, i want to do
it just for some particular classes. Is there any way to do this?

I know its possible to apply an aspect to all the classes by
redefining __metaclass__, and that I can do the same with a single
class by assigning to __metaclass__ inside the class definition.
However, I want to avoid the last step, so i can apply the aspect to
any class.

thanks!!

saludos! santiago.

I believe there is at least one AOP project out there somewhere.
I don't think you want to use metaclasses, though. If I wanted
to do that, I'd look at using descriptors, and installing them at
run time when I found I wanted to do the cut.

However, I'm not a big fan of AOP. I got my taste of intercepting
someone else's entry points in the '70s when I was hacking MVS.

John Roth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top