18 Questions
What is the purpose of @AfterReturning annotation in AOP?
To execute a method only when the join point method executes normally
What is the purpose of @AfterThrowing annotation in AOP?
To rollback the transaction declaratively when an exception is thrown
What is the purpose of a pointcut?
To identify the specific events with which advice should be associated
What is the most powerful type of advice in AOP?
Around Advice
What is the responsibility of around advice in AOP?
To invoke the join point method and return values if the method is returning something
When is after throwing advice executed in AOP?
Only when the join point method throws an exception
What is the primary purpose of an Aspect in AOP?
To implement enterprise application concerns that cut across multiple classes
What type of advice is executed after the join point method finishes executing, whether normally or by throwing an exception?
After (finally) advice
What is a join point in Spring AOP?
The execution of a method
What is the purpose of an advice in AOP?
To take actions for a particular joint point
What is the benefit of using AOP in terms of code maintenance?
Write less code and read less code
What can be used to define an aspect in Spring AOP?
Both XML configuration and Spring AspectJ integration
What is one of the main issues with Code tangling?
It breaks the linkage between requirement and its implementation
What is the term for code that is scattered across multiple abstractions?
Code scattering
What is the main issue with high-coupling?
It makes code harder to decompose
What is the purpose of a Logger in the given code?
To log messages
What is the relationship between a LoyaltyProgram and a CustomerCard?
A CustomerCard is part of a LoyaltyProgram
What is the main problem with boilerplate code?
It is hard to maintain
Study Notes
AOP Terminologies
- Aspect: A class that implements enterprise application concerns that cut across multiple classes, such as transaction management.
- Join point: A specific point in the application, such as method execution, exception handling, or changing object variable values. In Spring AOP, a join point is always the execution of a method.
- Advice: Actions taken for a particular joint point.
- Pointcut: Expressions that are matched with a joint point to determine whether advice needs to be executed or not, identifying specific events with which advice should be associated.
AOP Advice Types
- Before Advice: Runs before the execution of join point methods, using the @Before annotation.
- After Returning Advice: Executes only if the join point method executes normally, using the @AfterReturning annotation.
- After Throwing Advice: Executes only when the join point method throws an exception, using the @AfterThrowing annotation.
- Around Advice: Surrounds the join point method, allowing the choice to execute the join point method or not, using the @Around annotation.
AOP Benefits
- Centralize concerns implementation
- Intercept method calls
- Inject new behavior
- More reusable code
- Cleaner code
- Write less code
- More maintainable
- Read less code
- More concise and easy to understand
AOP Problems
- Code tangling
- Code scattering
- Poor traceability
- High-coupling
- Boilerplate code
- Difficult to decompose
Learn about different types of advice in Aspect-Oriented Programming, including after returning, after throwing, and around advice.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free