Home > Articles > Programming > Java

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

I18N Using Aspects: An Order Management Program

I'll start with a simple e-commerce application that allows you to create an order instance, to select items for purchase, and then to subtotal the order.

The following listing illustrates the program output. In the fourth line, the order is completed and sent for billing, at which point the total cost is calculated. Once billing is complete, some simple reporting is done on the order by displaying its financial value:

>java OrderManagement

Created an instance of StockItem
Created another instance of StockItem
Now routing the order to billing
Now in the after code
Date of order origination Fri Jul 07 11:55:49 BST 2006
Calculated order value 670.576
Order is complete, ready for reporting
Retrieved order value 670.576
Order has a value of 670.576

The amounts in the listing are numbers with no currency symbols or decimal points. Some fairly basic accounting applications will use this approach and don't add currency details. In this case, though, I want to be able to display the current dollar amount total for my order.

In keeping with my LTP requirements, I want to do this in as lightweight and noninvasive a fashion as possible. AOP allows for coding this either as part of an aspect or as a completely new aspect. The aspect code can then be dropped into the operational code (as described in the introduction of this article). Clearly, aspects aren't to everyone's taste; I must admit the purist in me does rebel a little at their lack of linearity. But similar arguments were made back in the RAM-constrained 1990s against code overlay tools. The key point here is that aspects provide a degree of programmer agility.

I have my problem requirement and my sketch of the solution. I'll now show you how it's done.

  • + Share This
  • 🔖 Save To Your Account