Answer question 1


/ Published in: Java
Save to your folder(s)

The idea is to create a proxy class that will delegate the increment and decrement call to MyIncDec implementation while measuring the time. To make it as transparent as possible, the proxy extends the IncDec interface. Beacuse a dependency to the actual IncDec implementation is required, the proxy constructor requires this implementation to be passed in as a parameter.
Furthermore, the code of the increment and decrement methods will still measure the duration even if an exception is thrown.

Because time measuring (performance analysis) is a cross cutting concern in a real system I would use AOP to define the timing logic just once and apply it to any method as required.

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.