00 Online Bookstore Lab
00 Online Bookstore Lab
00 Online Bookstore Lab
Carol McDonald
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
Browse Catalog
<<includes>> check out order items Add Order to Warehouse System (external)
<<includes>>
Send Receipt
: Customer
login
getProducts
addItem
checkOut
createOrder
updateInventory
sendOrderConfirmation
Customer Account Module: tracks Customer Account information Product Catalog Module: provides search for products, and product details Shopping Cart Module: allows user to save selected items for the session. Order Processing Module: performs order Processing when user buys the items in the cart. 1999 Sun Microsystems, Inc., All rights reserved. Copyright
Catalog
Cart
Order
Inventory Module: maintains information on the number of each type of product in stock. Messaging Module: sends confirmation receipt messages.
Control
Control Module: control interactions between user (browse, add items, check out) and business objects. (Servlets)
Copyright 1999 Sun Microsystems, Inc., All rights reserved.
browse
Catalog
Inventory
Cart
Order
View, Boundary, or Presentation classes: present the interface to the user Control classes: accept user requests and control the business objects to fulfill the request. Model classes: represent the application business data and rules.
Entity, Domain classes: usually abstractions of real world entities. Long lived, nouns. Session classes: business process, rules, workflow.
Copyright 1999 Sun Microsystems, Inc., All rights reserved.
Model
State query Notify Change Event View selection
State change
View
Controller
Servlets, or Controller classes Session EJB
The model is the heart of an application. It represents the application data and the business rules that govern access and modification of this data. The model serves as a software approximation to a real world process. Thus we can use simple real world modeling techniques when defining the model. The model abstraction provides: The ability for the view to query the model about its state. Notification to the view when the model changes. The ability for the controller to access application functionality encapsulated by the model. A view renders the contents of a model. It accesses data from the model and specifies how that data should be presented. When the model changes, it notifies the view. It is the views responsibility to maintain consistency in its presentation after a model change. When the view is rendered in a Web browser, it is generated as part of a response to a user request. In this scenario the treatment of model changes applies to parts of the model that might be cached in the Web server tier. 9
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., All rights reserved.
10
There is state associated both with the application user interface and with the application or business logic. In general, an application must maintain the follow-ing state: The user identity - Typically, the user account module maintains the user iden-tify, which includes the users login ID and certain security credentials. The search cursor and catalog position - The catalog module maintains the cur-sors position within the current search and within the catalog hierarchy. The items in the shopping cart - The shopping cart module maintains the list of items placed in the shopping cart. Order information - When the user commits the order, the shopping cart passes this information the order informationbilling address, shipping address, and payment methodto the order management module, which eventually stores it to a database.
11
0..n
The application maintains accounts and tracks orders for products. Thus, there are three areas for which data must be maintained: product, account, and order information. The product, category, and item tables represent the businesss product catalog. Each item has an associated entry in the inventory table that represents the inventory for that product. The account table maintains account information, one record per customer, with information such as customer name, password, and customer address. Finally, there is an orders table with one record per order, which keeps information about the order, including ship-to address, bill-to address, total price of the order, and payment (credit card name, expiration date, type) information. The orders table is linked to lineitem and orderstatus tables. Each item in an order is stored in a separate lineitem record, which contains the quantity ordered and price and a separate orderstatus record, which contains a reference to the item and the status of the order.
12
Customer
email
0..n
Order
orderId email
0..n
Product
ISBN
0..n
OrderLineItem
orderId lineNumber ISBN
13
14
15
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. 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, Customer, and Order) for each enterprise bean.
Copyright 1999 Sun Microsystems, Inc., All rights reserved.
Value Objects A value object is a business object that can be passed by value. The pass-byvalue semantics can be achieved by implementing the object as a serializable Java object. A business concept should be implemented as a value object when it is fine-grained, dependent, and immutable. There are two types of value objects: dependent objects and details objects. 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. Dependent objects have no set methods. Therefore, dependent objects can only be modified by creating a new containing object. Examples of dependent objects in the sample application are Address and CreditCard. A value object can also be used to encapsulate a serializable version of an entire remote object. Such objects are used to allow a client to retrieve the value of all the details of a remote object in one call. The sample application contains a details object named XXXModel (where XXX takes the values Catalog, Inventory, Account, Cart, and Order) for each enterprise bean.
16
17
A Catalog object represents different products and provides browsing and searching services to its clients. Both of the primary functions of the catalog, browsing and searching, are generic services which are not tied to any particular client. Also, the catalog object reads multiple rows in the database at the same time and provides a shared view of the data.
Copyright 1999 Sun Microsystems, Inc., All rights reserved.
A Catalog object represents different categories and products and provides browsing and searching services to its clients. Both of the primary functions of the catalog, browsing and searching, are generic services which are not tied to any particular client. Also, the catalog object operates on multiple rows in the database at the same time and provides a shared view of the data. The sample application uses stateless session beans for objects containing more than one database row. In particular, because stateless session beans provide high performance, stateless session beans are a good choice to provide a high-performance cache of data for operations that access multiple rows. In the sample application, the Catalog stateless session bean functions as a cache that is built up over time.
18
19
20
Controller Objects
Responsible for coordinating the Model and View. 1. Receives user requests, and translate them into application business events. 2. Invokes methods on the model to cause desired state changes. 3. Selects the screen shown in response to the request.
request
Customer
controller
display
event
model
view
Copyright 1999 Sun Microsystems, Inc., All rights reserved.
he Controller The sample application must reflect the state of a users interaction with the applica-tion and the current values of persistent data in the user interface. According to the MVC pattern, this functionality is assumed by the controller. In the sample applica-tion, the controller is split between the Web tier and the EJB tier. In this section we will discuss the implementation of the controller for the shopping interaction in the sample application. The controller is responsible for coordinating the model and view. The view depends on the controller for view selection. The model depends on the controller for making state changes to the model. The controller must accept user gestures from the view, translate them into a business events based on the behavior of the application, and process these events. The processing of an event involves invok-ing methods of the model to cause the desired state changes. Finally, the controller selects the screen shown in response to the request that was processed. Since the controller must coordinate both the view and the data, it straddles 21
DBMS
Order Entry
EJB Server
When using a distributed component model platform for providing a software solution, the goal of the application designer is to identify various components comprising a system. Our recommendation is to partition the system based on functionality, isolate the functional units of work, and identify the components that make up the function. For example, in this application we divided the application into following functional units: Customer Account Management, Order Management, Product Inventory Management, Catalog Management. Each functional unit can then be broken down in to various sub-components. For example, Customer Account management has a Web component to display and gather account information from the client, a business logic component to process the account information in accordance with some business rules, and a database component to store the persistent account information. The different components of an application need to follow certain design rules when communicating with each other.
22
Shopping cart
purchase
23
Servlet Login/Register
H T T P (S)
J D B C
Browse
Catalog
Purchase
Shopping Cart
Order
The Client interface is provided by servlets which generate HTML pages displayed in the browser. The servlet calls methods in the appropriate enterprise beans. The session bean ShoppingCart also acts as the client for the entity bean Order. The entity beans are stored in database tables - Order, Customer, (Product) .
24