Presentation & Business Tier Design Patterns
description
Transcript of Presentation & Business Tier Design Patterns
![Page 1: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/1.jpg)
Presentation & Business Tier Design Patterns
Pearce
![Page 2: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/2.jpg)
Definitions
• Pattern = reusable design
• Pattern Catalog = catalog of design patterns– Horizontal– Vertical
• Architectural pattern = Macro pattern = a composite pattern
![Page 3: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/3.jpg)
Four Tier Architecture
Client Tier
<<web browser>>
Presentation Tier
<<Web Server>>
Business Tier
<<App Server>>
Data Tier<<dbase server>>
HTTP
RMI
JDBC
JDBC
![Page 4: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/4.jpg)
Issues
• Migrating Business Logic from Presentation to Business Tier
• Providing B2B Business Tier
![Page 5: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/5.jpg)
The Model-View-Controller Macro Pattern
View Controller
Modelbusiness Tier
PresentationTier
![Page 6: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/6.jpg)
MVC Variations
• Service to Worker
• View-Dispatcher
![Page 7: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/7.jpg)
View-Dispatcher : Model : Controller : View : Client
dispatchfetch/update
content
command
![Page 8: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/8.jpg)
Service to Worker : Model : Controller : View : Client
update/fetch
content
dispatch
content
command
![Page 9: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/9.jpg)
Business Tier (Model) Patterns
• Entities
• Beans
• Value Objects
• Data Access Objects
• DAO Factories
• etc.
![Page 10: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/10.jpg)
Entities
• An entity is an object that represents a persistent business entity such as an account or a customer.
• Entities must persist between the sessions or transactions that use them.
• Entities are stored in files or databases
• Entities are beans– Simple or EJB.
![Page 11: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/11.jpg)
Java Beans
• A Java bean is an object that conforms to the Java Bean Component Model.– getters & setters for attributes– notifies listeners of attribute changes– serializable– etc.
![Page 12: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/12.jpg)
Example: A Person Entity
public class Person extends Entity { private String first; private String last; private Address address; private Phone phone; public Phone getPhone() { return phone; } public void setPhone(Phone p) { phone = p; } // etc.}
![Page 13: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/13.jpg)
Value Objects
• A value object holds the attributes of one or more entities in public fields.
• Pass value objects, not entities, between layers. This reduces network traffic.
• Value objects can update and create entities.
• Entities can create value objects.
![Page 14: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/14.jpg)
public class PersonVO extends ValueObject { public String first; public String last; public int addressOid; public String street; public String apartment; public String city; public String state ; public String zip; public int phoneOid; public String phone; public void update(Person per) { ... } public Person makePerson() { ... }}
Example: Person VO
![Page 15: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/15.jpg)
Entity
Phone
number
Address
streetapartmentcitystatezip
Person
lastfirst 1* 1*1 *1 *
ValueObject
oid : int
PersonVO
lastfirststreetapartmentcitystatezipaddressOidphonephoneOid
update()makePerson()
Bean<<serializable>>
Address Book
Entities
![Page 16: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/16.jpg)
Data Access Objects (DAOs)
• A DAO represents a data source.
• DAOs are created by DAO factories.
• DAOs hide the complexities of connecting with the underlying data source.
![Page 17: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/17.jpg)
Example: Person DAO
public interface PersonDAO { public int insert(PersonVO pvo) throws DAOException; public boolean delete(String name) throws DAOException; public PersonVO find(String name) throws DAOException; public boolean update(PersonVO pvo) throws DAOException;}
![Page 18: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/18.jpg)
DAOFactory
makePersonDAO()makeDAOFactory()
PersonDAO<<Interface>>
insert()update()delete()find()
DBaseDAO
MapPersonDAO
MapDAOFactory
makePersonDAO()
<<creates>>
DBasePersonDAO
DBaseDAOFactory
makePersonDAO()
<<creates>>
DAOs & Factories
![Page 19: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/19.jpg)
Presentation Tier Patterns(Controller and View)
• View
• View Helper
• Front Controller
![Page 20: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/20.jpg)
Front Controller
• Single access point for all forms.
• May verify & validate request
• May analyzes request
• May assemble business data needed by view (Service-to-Worker)
• Selects and dispatches to view
![Page 21: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/21.jpg)
View Helper
• Acts as intermediary between view and business tier
• Performs view-specific tasks
![Page 22: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/22.jpg)
View
• Generates HTML response
• View may assemble the data it needs (Dispatcher-View)
• Needed data may be assembled by controller (Service-to-Worker)
• Provides utilities for generating HTML
![Page 23: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/23.jpg)
Dispatcher-View Pattern
Helper
PersonHelperPersonDAO
<<Interface>>
1
1
1
1
DAOFactory
1
1
1
1
<<creates>>
View<<Servlet>>
requestresponseout
FrontController<<Servlet>>
processRequest()dispatch()
PersonView
11 11
dispatchesTo
![Page 24: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/24.jpg)
: FrontController : PersonView : PersonHelper : DAOFactory : PersonDAO
container dispatch
creates
execute(cmmd)
makeDAO()
creates
cmmd
result
makeBody()
dispatch
makeBody()
execute(cmmd)
cmmd
result
![Page 25: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/25.jpg)
GenericServlet
HttpServlet
doGet()doPost()doPut()doDelete()
ServletRequest<<Interface>>
getParameters()
HttpServletRequest<<Interface>>
ServletResponse<<Interface>>
HttpServletResponse<<Interface>>
ServletContainerServletConfig<<Interface>>Servlet
<<Interface>>
init()service()destroy()
*1 *1 11
View
getHelper()
RequestDispatcher<<Interface>>
forward()include()
PersonView
ServletContext<<Interface>>
getAttribute()setAttribute()getRequestDispatcher()
11
**
Helper*
typetype
*
PersonHelper
PersonDAO
![Page 26: Presentation & Business Tier Design Patterns](https://reader036.fdocuments.us/reader036/viewer/2022062315/568159e6550346895dc731e6/html5/thumbnails/26.jpg)
Every Servlet has 3 AMaps
HttpServlet
ServletRequest<<Interface>>
getParameters()getAttribute()setAttribute()
HttpSession
getAttribute()setAttribute()
ServletContext<<Interface>>
getAttribute()setAttribute()getRequestDispatcher()
AMap
Map<<Interface>>