Intercepting Function Calls Using Proxy
Let’s discuss the three types of aspect-oriented programming.
Aspect-oriented programming (AOP) is a special case of metaprogramming where function calls may be intercepted with advices.
An advice is a piece of code that is exercised in a particular context.
In life we often receive three kinds of advice:
- Good
- Bad
- Unsolicited
AOP also has three kinds of advice:
- Before advice: runs before the intended function call
- After advice: runs after the intended function call
- Around advice: runs instead of the intended function
Uses of AOP
Logging is the most infamous example of AOP advice since it’s overused by authors. For informational or debugging purposes, we may inject a call to log parameters passed to a function. Additionally, we may log the result of a function call before it’s passed back to the caller.
There are many other uses of AOP advices. For instance, we may use them to monitor the context of a function call’s execution, to check for authorization or permission to call, to alter arguments passed ...