I am implementing a abstract Java class of a processing framework*. By implementing the function
execute, I am able to add business logical functionality. I would like to add logging at the start and end of every implementation of every of my execute functions. Also in between some logging, if specific things are done. However, I would like to make this in a uniform manner. My thought was to inherit the framework class to an own new class which implements the logging and provides some new
executeWithLogging functions, which are wrapping the logging around the specific parts. I am not sure if that is the best idea and whether I am able to use a design pattern that would make the whole endeavor elegant. How would I go on about the whole thing?
Challenges (please consider these!)
- One challenge in my case is that the original class has only one
executefunction, however, I'd need logging around multiple parts.
- The second thing is: Using a decorator pattern (was my first idea as well) does not quite work, if I am using also a
execute, because the
super.execute()-function would have to be called in the first line of my new
execute(), isn't it?
- There would be at least 4 classes involved:
BaseFunctionfrom the framework,
LoggingFunction extends BaseFunctionfrom me,
MyBusinessFunction extends LoggingFunctionfrom me,
- Not only do I need logging at the beginning and end of
execute, but also in the middle.
- The "logging" is not just simple Java logging, but actually logging to a database. This does not change anything about the principles, but demonstrates that the logging might be more than just one line of code.
Maybe an example how I'd do the whole thing would be nice, to get me going.
|* A Storm Trident Function, similar to a Storm bolt, but this is not particularly important.