Professional Documents
Culture Documents
Lab Exercises Online Bookstore Application: Carol Mcdonald
Lab Exercises Online Bookstore Application: Carol Mcdonald
Application
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
Customer
Login to Customer Account
add items to shopping cart
<<extend>>
<<includes>>
check out order items
<<includes>>
Send Receipt
Catalog
Shopping
Cart
Order
Inventory
Mailer
: Customer
login
getProducts
addItem
checkOut
createOrder
updateInventory
sendOrderConfirmation
Catalog
Cart
Order
Control
browse
Catalog
Control
new/existing account
add/remove
items
Cart
Account
checkout
Inventory
Order
Model
State
query
View
State change
Notify Change
Event
View selection
Controller
User event
JSP
JavaBeans
components
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
Process
/service
control
Servlet
Session Bean
Receives request
Validates input
Calls session bean
Call JSP
HTML
layout
Validates request
Executes process
Enforces transactions
model
Entity Bean
JSP
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
Orders
orderid
email
date
ShipAddress
Total price
1
0..n
Product
ISBN
title
author
description
OrderLineItem
orderId
linenumber
ISBN
quantity
Unit price
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
0..n
Order
orderId
email
email
1
0..n
Product
ISBN
0..n
OrderLineItem
orderId
lineNumber
ISBN
13
Customer
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
password
name
address
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
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()
u
e
e
e
e
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 ( )
14
orders
orderid
emailId
date
ShipAddress
Total price
lineitem
orderId
linenumber
itemId
quantity
Unit 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()
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
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()
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
controller
event
model
Customer
display
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
EJB Container
Catalog
Customer Account
Servlets
Servlets
Shopping
Cart
Order Entry
EJB Server
22
Shopping
cart
show
products
purchase
catalog
customer
Order
23
Servlet
H
T
T
P
(S)
Enterprise JavaBean
Login/Register
Customer
Browse
Catalog
Shopping
Cart
Purchase
J
D
B
C
Order
JNDI
Directory Server
Copyright 1999 Sun Microsystems, Inc., All rights reserved.
24