I want to keep logging code separate from my domain logic using aspects
. But those aspects
should do compile time weaving rather than making proxy objects.
What all options are there apart from AspectJ
?
I want to keep logging code separate from my domain logic using aspects
. But those aspects
should do compile time weaving rather than making proxy objects.
What all options are there apart from AspectJ
?
Well, another approach to deal with transversal concerns, as logging, is to use Command Pattern. This way, you can use a ServiceDelegate to control all command runs and in this place take control of every transversal concern.
For example, every command must inherit from an abstract class which define a runCommand
method. Then a ServiceDelegate
is invoked to run a command this way:
//take control of pre conditions
if(command.isAuthEnabled)
//do what you want
command.runComman();
//take control of post conditions
if(command.isLogEnabled())
//do what you want
Maybe this sound strange, but it is an alternative to use aspects. It is not better or worse, it is different and it will be scenarios where aspect would fit better, and other where command would be nice.