I have a need for methods in several classes that must always follow a specific pre and post pattern.
public void method(X x, Y y ) {
// ********Repeating Part begin **************/
AFrameworkClass aFrameworkClass = new AFrameworkClass (this.memberVariable,"SomeString");
try {
aFrameworkClass.aFrameworkMethod( x,y);
aFrameworkClass.anotherFrameworkMethod(x,y);
aFrameworkClass.yetAnotherFrameworkMethod(x);
aFrameworkClass.doPreProcessing();
Throwable t = null ;
// ********Repeating Part End **************/
try {
// code will vary according to the business logic
}
catch (Throwable t) {
// code will vary according to the business logic
}
// ********Repeating Part begin **************/
aFrameworkClass.doPostProcessing();
} finally { aFrameworkClass.doCleanup();
}
// ********Repeating Part End **************/
}
Is it possible to use Spring framework to accomplish the logic in the repeating parts in this method without having to code those lines over and over again in my various classes? If so how?