MoneyFactory.

Power Java
Dynamic Proxy Classes:
Toward Metalevel Programming in Java

Mathias Richter and Takashi Suezawa
Listing 4. MoneyFactory.


public class MoneyFactory
{
   public static IMoney newMoney(String currency, double amount)
   {
	    IMoney result = null;
	    try
       {
         MoneyInvocationHandler handler = null;
         Money primary = new Money( currency, amount );
         handler = new MoneyInvocationHandler (primary);
         result = (IMoney) Proxy.newProxyInstance(primary.getClass().getClassLoader(),
                 new Class[] { IMoney.class }, handler);
	    } catch(Exception e)
          {
          System.out.println( e.getMessage() );
        } finally
        {
          return result;
       }
   }
}

Upcoming Training Events

0 AM
Visual Studio Live! San Diego
September 8-12, 2025
Live! 360 Orlando
November 16-21, 2025
Cloud & Containers Live! Orlando
November 16-21, 2025
Data Platform Live! Orlando
November 16-21, 2025
Visual Studio Live! Orlando
November 16-21, 2025