Monday, February 20, 2006

AOP Around Advice and Python's Way of Exposing Properties

I just read the part of The AspectJ Programming Guide about the "around" advice.  What the around advice does is that every time a method is called that matches your criteria (for example, all methods that begin with "set" in certain classes), it runs the code in the advice instead of the code in the method.

This reminds me of what Butch told me about the Python language.  In Python, the fields of a class are public by default!  This is shocking for Java programmers.  I know it was shocking to me - doesn't that make for rigid code?  Butch said no, because later on you can redirect the call to the field to instead run a method.  This is similar to around advice, only on fields.

I think that Python's way of exposing properties is a lot better than Java's, where you expose attributes through getters and setters.  It's actually such a maintenance bother to manage those methods, even with an IDE.  Not to mention the clutter in your code - the idea for the property is already expressed in the attribute, so expressing it doesn't make sense to express each attribute twice more as a getter and setter method. 

No comments:

Post a Comment