Lab Exercises Online Bookstore Application

Carol McDonald

1

Sample Application
Review process of developing application from specification to design to implementation. 1. Scenarios or Use Cases 2. Partitioning of functionality into modules 3. Assignment of functionality to tiers 4. Model View Controller Design Pattern 5. Business Logic Classes

© Copyright 1999 Sun Microsystems, Inc., All rights reserved.

2

3 . All rights reserved.Use Case Scenarios C reate/Update Custom e r Account Browse Catalog Customer Login to Customer Account add items to shopping cart <<extend>> <<includes>> check out order items Add Order to Warehouse System (external) <<includes>> Send Receipt © Copyright 1999 Sun Microsystems. Inc..

Divide the Application Into Modules Based on Functionality Account Catalog Shopping Cart Order Inventory Mailer : Customer login getProducts addItem checkOut createOrder updateInventory sendOrderConfirmation © Copyright 1999 Sun Microsystems. All rights reserved.. Inc. 4 .

and product details Shopping Cart Module: allows user to save selected items for the session.Divide the Application Into Modules Based on Functionality Account Customer Account Module: tracks Customer Account information Product Catalog Module: provides search for products. All rights reserved. Inc.. Order Processing Module: performs order Processing when user buys the items in the cart. 1999 Sun Microsystems. © Copyright Catalog Cart Order 5 .

6 . Mail Control Control Module: control interactions between user (browse. (Servlets) © Copyright 1999 Sun Microsystems. All rights reserved.Divide the Application Into Modules Based on Functionality Inventory Inventory Module: maintains information on the number of each type of product in stock. Inc. check out) and business objects. Messaging Module: sends confirmation receipt messages. add items..

.Interrelationship of the modules User interface Control browse Catalog new/existing account add/remove items checkout Account Inventory Cart Mail Order © Copyright 1999 Sun Microsystems. 7 . All rights reserved. Inc.

Inc.. Long lived. Boundary. © Copyright 1999 Sun Microsystems. • Session classes: business process. • Entity. or Presentation classes: present the interface to the user – Control classes: accept user requests and control the business objects to fulfill the request. All rights reserved.Divide Application into Objects • Divide Application Objects into 3 categories: – View. – Model classes: represent the application business data and rules. 8 . Domain classes: usually abstractions of real world entities. nouns. workflow. rules.

it is generated as part of a response to a user request. When the view is rendered in a Web browser. In this scenario the treatment of model changes applies to parts of the model that might be cached in the Web server tier. Thus we can use simple real world modeling techniques when defining the model. The model serves as a software approximation to a real world process. 9 . • The ability for the controller to access application functionality encapsulated by the model. Inc. The model abstraction provides: • The ability for the view to query the model about its state.Model View Controller Design Pattern Entity EJB and Session EJB Model State query Notify Change Event View selection State change View Controller Servlets. The model is the heart of an application. All rights reserved. • Notification to the view when the model changes. It represents the application data and the business rules that govern access and modification of this data. When the model changes. It is the view’s responsibility to maintain consistency in its presentation after a model change. or Controller classes Session EJB User event JSP JavaBeans components © Copyright 1999 Sun Microsystems. it notifies the view. It accesses data from the model and specifies how that data should be presented. A view renders the contents of a model..

All rights reserved.. 10 .MVC Presentation Logic Layout Application Logic Business Data Access data model Entity Bean Manages data control Servlet Receives request Validates input Calls session bean Call JSP Process /service Session Bean Validates request Executes process Enforces transactions HTML layout JSP model Entity Bean Formats HTML Manages data Responds to client © Copyright 1999 Sun Microsystems. Inc.

the shopping cart passes this information the order information—billing address. • Provides object wrapper for accessing and manipulating the data. Inc. All rights reserved.Typically. shipping address.The shopping cart module maintains the list of items placed in the shopping cart. Often Nouns. long lived. • Order information . • Persistent .The catalog module maintains the cur-sor’s position within the current search and within the catalog hierarchy. • The items in the shopping cart . an application must maintain the follow-ing state: • The user identity . and payment method—to the order management module.When the user commits the order. In general.. which includes the user’s login ID and certain security credentials. 11 . © Copyright 1999 Sun Microsystems. which eventually stores it to a database. There is state associated both with the application user interface and with the application or business logic. • The search cursor and catalog position . • Entity Beans: Object view of business entity stored in persistent storage. the user account module maintains the user iden-tify.Model: Business Objects: Business Data • Often called domain classes since they deal with abstractions of real-world entities.

and payment (credit card name... Inc. The account table maintains account information. which contains a reference to the item and the status of the order.n Product ISBN title author description OrderLineItem orderId linenumber ISBN quantity Unit price © Copyright 1999 Sun Microsystems. there is an orders table with one record per order. expiration date. type) information. Finally. All rights reserved. The product. Each item has an associated entry in the inventory table that represents the inventory for that product. Thus. total price of the order. including ship-to address. password. and order information. The application maintains accounts and tracks orders for products. with information such as customer name. and item tables represent the business’s product catalog. 12 . Each item in an order is stored in a separate lineitem record. there are three areas for which data must be maintained: product. and customer address.Online BookStore Database Schema 1 Customer email password name address 0-n Orders orderid email date ShipAddress Total price 1 0. which keeps information about the order. category. The orders table is linked to lineitem and orderstatus tables. account. one record per customer. bill-to address. which contains the quantity ordered and price and a separate orderstatus record.

.n OrderLineItem orderId lineNumber ISBN © Copyright 1999 Sun Microsystems.UML for Entity Objects Customer email 1 0. All rights reserved.. 13 .n Order orderId email 1 0..n Product ISBN 1 0.. Inc.

All rights reserved. Inc. 14 ..Customer Entity EJB C u s t o m e rE J B e m a il a d d res s nam e p a s s w o rd c r e d i t C a rd N u m b e r s e t C u s to m e r D e ta i l s ( ) g e t C u s to m e r D e ta i l s ( ) lo g in ( ) e e e e s u e e e e j b C r e a te ( ) j b P o s tC r e a t e ( ) jb F in d B yN a m e () jb R e m o ve ( ) e tE n tityC o n te xt() n s e tE n tityC o n te x t ( ) jb A c tiva te ( ) jb P a s s iva te ( ) jb L o a d () j b S to r e ( ) Customer email password name address © Copyright 1999 Sun Microsystems.

. All rights reserved. 15 . Inc.Order Entity EJB orders orderid emailId date ShipAddress Total price OrderEJB orde rId orderLineItem s email s ta tu s to talPrice orde rDate getOrderDeta i l s () ejbCreate() ejb R e m ove() s e tEntityContext() ejb L o a d () ejb S tore() ejbFind ByPrim a ryK e y() ejb Activate() ejb P a s s ivate() 1 n lineitem orderId linenumber itemId quantity Unit price © Copyright 1999 Sun Microsystems.

Value Objects A value object is a business object that can be passed by value. and immutable. A value object can also be used to encapsulate a serializable version of an entire remote object. The pass-byvalue semantics can be achieved by implementing the object as a serializable Java object. An object is a dependent object of another object if its life cycle is completely managed by that object and if it can only be accessed indirectly through that object. Inventory. Dependent objects have no set methods. and Order) for each enterprise bean. Account. A business concept should be implemented as a value object when it is fine-grained. Examples of dependent objects in the sample application are Address and CreditCard. Therefore. All rights reserved. 16 . Inc. This allows to retrieve the value of all the details of a remote object This App has details objects named XXXDetails (where XXX takes the values Book. Such objects are used to allow a client to retrieve the value of all the details of a remote object in one call. Customer. dependent objects can only be modified by creating a new containing object. dependent. There are two types of value objects: dependent objects and details objects. The sample application contains a details object named XXXModel (where XXX takes the values Catalog. Cart..Value Objects CustomerEJB email address name password creditCardNumber setCustomerDetails() getCustomerDetails() login() ejbCreate() ejbPostCreate() ejbFindByName() ejbRemove() setEntityContext() unsetEntityContext() ejbActivate() ejbPassivate() ejbLoad() ejbStore() CustomerDetails email address name password cred itCardNum ber getEmail() g e tA d d r e s s ( ) getName() getPassword() g e tC reditCardNumber() Value objects are used to encapsulate a serializable read only version of an entire remote object. and Order) for each enterprise bean. © Copyright 1999 Sun Microsystems.

Workflow • Stateless Session Beans: – Reusable service objects – May provide high performance – Need to operate on multiple rows at a time – Provides procedural view of data © Copyright 1999 Sun Microsystems.Model: Business Objects: Business Rules. Process. 17 . Inc.. All rights reserved.

are generic services which are not tied to any particular client. A Catalog object represents different categories and products and provides browsing and searching services to its clients. are generic services which are not tied to any particular client.. because stateless session beans provide high performance. the catalog object reads multiple rows in the database at the same time and provides a shared view of the data. stateless session beans are a good choice to provide a high-performance cache of data for operations that access multiple rows. In particular. © Copyright 1999 Sun Microsystems. browsing and searching. Also. All rights reserved. Both of the primary functions of the catalog. In the sample application. Both of the primary functions of the catalog.Stateless Services: Catalog Session EJB product ISBN title author description CatalogEJB getBooks() getBookDetails() findBooksBySubject() ejbCreate() s e tSessionContext() e j b R e m o ve() ejbActivate() ejbPassivate() A Catalog object represents different products and provides browsing and searching services to its clients. the Catalog stateless session bean functions as a cache that is built up over time. browsing and searching. 18 . The sample application uses stateless session beans for objects containing more than one database row. Inc. the catalog object operates on multiple rows in the database at the same time and provides a shared view of the data. Also.

Process.Model: Business Objects: Business Rules.. All rights reserved. process management © Copyright 1999 Sun Microsystems. Workflow • Stateful Session Beans – Maintain client specific state – Non-persistent – Workflow. 19 . Inc.

Stateful Session EJB ShoppingCartEJB cart numberOfItems addItem () deleteItem () clear() getItem s () getItem () getNumberOfItems() getTotal() ejbCreate() s e tSessionContext() ejbRemove() ejbActivate() ejbPassivate() © Copyright 1999 Sun Microsystems. 20 . Inc.. All rights reserved.

1. 3. Selects the screen shown in response to the request. and translate them into application business events. request Customer controller display event model view © Copyright 1999 Sun Microsystems. The controller is responsible for coordinating the model and view. he Controller The sample application must reflect the state of a user’s interaction with the applica-tion and the current values of persistent data in the user interface. the controller selects the screen shown in response to the request that was processed. The processing of an event involves invok-ing methods of the model to cause the desired state changes. The model depends on the controller for making state changes to the model. All rights reserved. and process these events. it straddles 21 . Invokes methods on the model to cause desired state changes. According to the MVC pattern. Receives user requests. the controller is split between the Web tier and the EJB tier.. The view depends on the controller for view selection. this functionality is assumed by the controller. The controller must accept user gestures from the view. In the sample applica-tion. In this section we will discuss the implementation of the controller for the shopping interaction in the sample application. Since the controller must coordinate both the view and the data. 2. translate them into a business events based on the behavior of the application. Finally. Inc.Controller Objects Responsible for coordinating the Model and View.

Order Management. Product Inventory Management. For example.Example Solution: EJBs Clients Web Server Application Server EJB Container Catalog Servlets Servlets Shopping Cart Customer Account DBMS Order Entry EJB Server © Copyright 1999 Sun Microsystems. Catalog Management. isolate the functional units of work. in this application we divided the application into following functional units: Customer Account Management. Customer Account management has a Web component to display and gather account information from the client. the goal of the application designer is to identify various components comprising a system.. and identify the components that make up the function. All rights reserved. 22 . a business logic component to process the account information in accordance with some business rules. Our recommendation is to partition the system based on functionality. The different components of an application need to follow certain design rules when communicating with each other. Each functional unit can then be broken down in to various sub-components. Inc. When using a distributed component model platform for providing a software solution. For example. and a database component to store the persistent account information.

All rights reserved.Example Scenario continued Servlets add to cart register or login show products Shopping cart purchase catalog customer Order © Copyright 1999 Sun Microsystems.. 23 . Inc.

All rights reserved. The session bean ShoppingCart also acts as the client for the entity bean Order..Order.Example Scenario continued Servlet Login/Register H T T P (S) Enterprise JavaBean Customer J D B C Browse Catalog Purchase Shopping Cart Order Enterprise Application Server Server Configuration JNDI Directory Server © Copyright 1999 Sun Microsystems. Inc. The Client interface is provided by servlets which generate HTML pages displayed in the browser. The servlet calls methods in the appropriate enterprise beans. Customer. (Product) . The entity beans are stored in database tables . 24 .

Sign up to vote on this title
UsefulNot useful