E-Commerce

The basic abstraction in E-commerce applications is a virtual shopping cart. Users can add and remove items from their carts. When it's time to check out, the cart computes the total of all items in the cart. Of course the total also includes the sales tax and shipping costs. These costs depend on where the customer lives and which shipping method he selected: air, land, or sea.

One way to account for these variations is to introduce different types of shopping carts:

aaa

This quickly leads to a large, unmanageable hierarchy with lots of code duplication. In addition, if a customer changes his mind about shipping, say, then the old cart must be replaced by a new cart containing the same items.

We can encapsulate the strategies for computing sales tax and computing shipping costs in separate strategy objects:

aaa