A more sophisticated MoneyLogger.

Power Java
Dynamic Proxy Classes:
Toward Metalevel Programming in Java

Mathias Richter and Takashi Suezawa
Listing 9. A more sophisticated MoneyLogger.


public class MoneyLogger
     extends Aspect
     implements IMoney
{

	  private double fOldAmount;
	  ... // implementation of other methods

	  public void setAmount(double amount)
	  {
	    IMoney primary = (IMoney)getPrimary();
	    if ( getPhase() == BEFORE )
           fOldAmount = primary.getAmount();
	    if ( getPhase() == AFTER )
		   System.out.println( primary + ": Set amount from " +
                                  fOldAmount + " to " + amount );
	  }
}