Spring – AOP
Before learning how to implement Aspect-oriented programming with Spring, we should first learn what Aspect-oriented programming is. The definition of Aspect-oriented programming says it is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding additional behavior to existing code (an advice) without modifying the code itself.
Now, what did we mean by cross-cutting concerns? Let's explore.
In a real-life project, multiple components play their own role. For example, if we take our previous scenario into account, the Student
class itself is a component, similarly there could be a faculty component who would evaluate the student based on his/her performance. So, let's add a faculty to our program.
The Faculty
class should be simple enough, with just a method to evaluate a student. Just as follows:
class Faculty { fun evaluateAssignment() { val marks = Random().nextInt(10) println...