My little example of Aspect-Oriented Programming
I have been reading the SpringFramework for like 2 days and AOP. I just want to give out an example of AOP. I don’t want to use and technical words, such as Point-cut, or advice, etc, because It’s too hard to define those words for me. ^_^
I will present the easiest example. If developers want to add more function to a class, like logging. The code in classes will be like mess. Like these
// codes for logging
// your codes //transaction code
// another code
It’s too mess for production. Here the AOP would help you. You can add logging method to your production and create a XML or configuration (AOP configuration) and let the method you just created execute before or after your execution point or even around. This solution would not affect you production at all, because the logging code runs across your production not with your production. If developers feel bad about the new code, they can just drop it out of the production. It would not affect your production at all. It’s like the new code run across the old code.

Here’s your transaction service, and you would like to add logging service to your production.

an OOP would be like this. The logging service would run along with the transaction service. Developers have to decode the production or might have to redeploy the production again. What if you cannot drop the production, because it’s running?

Here’s the AOP comes and helps developers. Developers create logging service without to decode the production or even drop the production off. They just create a logging service and deploy the logging service which runs across with the production. It’s called Cross-cutting concerns. The production would not be affected at all.






