Java Reference
In-Depth Information
@Aspect
public class CalculatorLoggingAspect {
...
@Before("CalculatorPointcuts.parameterPointcut( target, a, b)")
public void logParameter( Object target, double a, double b) {
log.info("Target class : " + target.getClass().getName());
log.info("Arguments : " + a + ", " + b);
}
}
1-14. Introducing Behaviors to Your Beans
Problem
Sometimes you may have a group of classes that share a common behavior. In OOP, they must extend
the same base class or implement the same interface. This issue is actually a crosscutting concern that
can be modularized with AOP.
In addition, the single inheritance mechanism of Java allows a class to extend only one base class at
most. So you cannot inherit behaviors from multiple implementation classes at the same time.
Solution
Introduction is a special type of advice in AOP. It allows your objects to implement an interface
dynamically by providing an implementation class for that interface. It seems as if your objects had
extended the implementation class at runtime.
Moreover, you are able to introduce multiple interfaces with multiple implementation classes to
your objects at the same time. This can achieve the same effect as multiple inheritance.
How It Works
Suppose you have two interfaces, MaxCalculator and MinCalculator , to define the max() and min()
operations.
package com.apress.springenterpriserecipes.calculator;
public interface MaxCalculator {
public double max(double a, double b);
}
package com.apress.springenterpriserecipes.calculator;
public interface MinCalculator {
public double min(double a, double b);
}
 
Search WWH ::




Custom Search