Programmers used to more dynamic, reflective languages like Lisp Language, Smalltalk Language, Python Language, or Ruby Language can be found puzzling about what is new enough about this to give it an "*OrientedProgramming" name.
AOP is just an extension of Object Oriented Programming. Both of these tools allow us to more easily achieve Code Normalization.
The Ruby Language also lets you do this – you can (for example) change the behavior of method invocation or attribute access on a particular object or class of objects, all at run time. For example, you could define your own tracing capability, point it at an object, and suddenly that object traces all accesses to its attributes, all with no change to that object's source. Once you have decent reflection and metaclasses, AOP is just part of the language. -- David Thomas
Could you offer an example that would clarify this, please? :)
Any OO language lets you define class methods, like so:
# User.rb class User def getRank self.rank end ... end
Ruby also lets you define, at runtime, methods on a predefined class, outside of that class' original definition. This lets you do things such as, say, add a method to a predefined class:
# UserPlus.rb # User was already defined in User.rb, but let's add one more method here class User def selfEsteemProgram true end end
In Python, this can be done as:
# User class already defined, but we add another method here User.selfEsteemProgram = lambda x: True
Back to Ruby, you can also define, at runtime, methods on individual objects:
# happyUsers.rb myUser = User.new if selfEsteemProgram def myUser.getRank "Supervisor" end end
And in Python:
myUser = User() if myUser.selfEsteemProgram(): def f(x): return "Supervisor" import new myUser.getRank = new.instancemethod(f, myUser, myUser.__class__)
Also, Ruby's Mix Ins or Python's Meta Classes might be enough to take care of what AOP is supposed to do.
For Python, see Pyarie (pyarie.wikisophia.org ), which uses the Pythius (pythius.sf.net ) AOP module. Also Trans Warp seems to have had some Aspect aspect. (www.zope.org ). And, finally, there's www.logilab.org .
For a more detailed/better example of AOP in Ruby, and a rewrite of an AOP refactoring tutorial from www.theserverside.com , see homepages.ihug.com.au . -- Anonymous Donor
Io Language has similar capabilities to Ruby's. -- Jason Grossman
See original on c2.com