The shopping cart bean shown below encapsulates the business processing necessary to maintain the user's shopping cart. The bean contains not only the get and set methods for the shopping cart contents but the addMovies method, used to add a collection of movies to the shopping cart, and the deleteMovies method, which allows a collection of movies to be deleted from the shopping cart.
The ShoppingCartBean uses an internal DAO and value object to manage the shopping bean state. A getItemCount method is used to return the count of items in the shopping cart, used by one of the action classes to determine whether or not the cart is empty. (In Chapter 35 we examine how to implement this as an EJB.)