Aspect-Oriented Programming
- Posted by Shaun on November 14th, 2005 filed in Java, Technology
- Comments Off
I’ve been reading up on the Spring Framework for a new project at work. It mentioned AOP or Aspect-Oriented Programming. I never heard of it before so I read an article on Answers.com regarding AOP. It is an interesting concept.
Object-Oriented Programming basically says that things should be encapsulated into modules. AOP takes this concept one step further and provides ways to encapulate aspects of an application that OOP cannot.
For example, if you are using OOP and your object methods require the user to be logged into the system you need to add code to each method to check if the user is logged in or not (authentication). This can be tedius to do and if you need to change this authorization code you need to make changes in a number of places.
AOP allows you to encapsulate this authentication into a module and then use rules to apply the module to different modules. i.e. you could in theory encapsulate the authentication code into a module and then apply a rule that says for each method invokation you need to first call a method in this authentication module.
I’m not sure how Spring accomplishes AOP, but it could be handy at times. It is a bit different in concept from OOP, but I think it is interesting. I’ll have to look into it further.