Using multimethods, we can add methods to existing Java classes. My question is whether it is possible to override one specific method and how, from Clojure code. For example, if you have the following class,
public class Shape { public void draw() { ... } }
I would like to be able to run something to add a before method, for example:
(attach-to-method Shape/draw :before (println "... about to draw a shape"))
And after evaluating this form, all subsequent drawing calls will begin to print a line before making the call itself.
My goal with this application before / after / around, behavior similar to AOP, is that the infrastructure calling this method in an existing instance can dynamically change and run the newly connected code. I am currently using AspectJ for this, but I get to the point where using another compiler is not an option, and I'm curious to know if I can just stop AspectJ.
aop clojure
Edgar
source share