AOP and metaclasses

Discussion in 'Python' started by Santiago Aguiar, Feb 20, 2004.

  1. 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.
    Santiago Aguiar, Feb 20, 2004
    #1
    1. Advertising

  2. Santiago Aguiar wrote:
    > 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.

    --
    Shalabh
    Shalabh Chaturvedi, Feb 20, 2004
    #2
    1. Advertising

  3. Santiago Aguiar

    John Roth Guest

    "Santiago Aguiar" <> wrote in message
    news:...
    > 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
    John Roth, Feb 20, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ravi Shankar Nair

    Regarding AOP - Performance and Security

    Ravi Shankar Nair, Dec 21, 2005, in forum: Java
    Replies:
    3
    Views:
    572
    Chris Smith
    Dec 21, 2005
  2. Twisted

    AOP and debugging

    Twisted, Mar 1, 2006, in forum: Java
    Replies:
    0
    Views:
    994
    Twisted
    Mar 1, 2006
  3. Rustom Mody

    AOP and pep 246

    Rustom Mody, Nov 1, 2007, in forum: Python
    Replies:
    13
    Views:
    526
    Kay Schluehr
    Nov 13, 2007
  4. George  Moschovitis
    Replies:
    0
    Views:
    107
    George Moschovitis
    Apr 18, 2005
  5. Luís Miguel Lourenço

    AOP and Ruby

    Luís Miguel Lourenço, May 24, 2005, in forum: Ruby
    Replies:
    4
    Views:
    131
    Lionel Thiry
    May 24, 2005
Loading...

Share This Page