CHAPTER 11 Implementing conversations To process the event, (My web server)
CHAPTER 11 Implementing conversations To process the event, you need to execute a sequence of operations: check the winning bid for the auction, charge the cost of the auction, notify the seller and winner, and so on. You could write a single class that has one big procedure. A better design is to move the responsibility for each of these steps into reusable smaller components and to separate them by concern. We ll have much more to say about this in chapter 16. For now, assume that you followed our advice and that several classes need to be called inside the same unit of work to process the closing of an auction. 11.1.1 The use case for Session propagation Look at the code example in Listing 11.1, which controls the processing of the event. Listing 11.1 Controller code that closes and ends an auction public class ManageAuction { ItemDAO itemDAO = new ItemDAO(); PaymentDAO paymentDAO = new PaymentDAO(); public void endAuction(Item item) { // Reattach item itemDAO.makePersistent(item); // Set winning bid Bid winningBid = itemDAO.getMaxBid( item.getId() ); item.setSuccessfulBid(winningBid); item.setBuyer( winningBid.getBidder() ); // Charge seller Payment payment = new Payment(item); paymentDAO.makePersistent(payment); // Notify seller and winner … } … } The ManageAuction class is called a controller. Its responsibility is to coordinate all the steps necessary to process a particular event. The method endAuction() is called by the timer (or user interface) when the event is triggered. The controller doesn t contain all the code necessary to complete and close the auction; it delegates as much as possible to other classes. First, it needs two stateless service
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.