Design and maintenance of J2EE web apps

Download Report

Transcript Design and maintenance of J2EE web apps

Design and Maintenance of
J2EE Web Applications
Upsorn Praphamontripong
CS 4640
Programming Languages for Web Applications
Spring 2017
Overview: Design and Maintenance Issues
1.
JSP maintenance issues
2.
General design issues
3.
Tiered architectures
4.
Page centric and dispatcher designs
5.
Model view controller
CS 4640
2
1. JSP Maintenance Problems
• Presentation and content are frequently mixed
• Java mixed with HTML can be very difficult to understand, modify, and
debug
• Most books, articles, and web resources focus on JSP syntax,
not style and design
CS 4640
3
First Rule of Formatting JSP
• JSP could be very messy
• Hard to read
• Hard to debug
• Hard to get right
• Hard to maintain
• Strategy:
• Keep a minimum of Java in the JSP
• Do most of the programming (backend) with separate Java:
• Servlets and beans
• This allows separation of concerns – good OO design
CS 4640
4
JSP: Readable HTML
• Make JSP look like HTML with Java calls, not Java with some
HTML
• Move all of the business logic out of the JSP
• Java that generates HTML is hard to maintain:
• Human have trouble viewing HTML as “normal text”
• The quotes inside quotes are very hard to read
• e.g., “<a href=\“login.jsp\”>”
• Let HTML developers write HTML, and Java developers write
Java
CS 4640
5
2. General Design Issues
• Major design goals of web app design is separation of concerns
• Presentation
• Logic
• Data
• Seven criteria the design should support:
1.
Reliability
2.
Usability
3.
Security
4.
Availability (and also Accessibility)
5.
Scalability
6.
Maintainability
7.
Performance and Time to market
CS 4640
6
Separation of Concerns
Presentation
HTML and JSP
Logic
Java classes (non-servlet)
Data
• Data content
Servlets and beans
• Data representation
Data structure, beans, Java classes
• Data storage
Database and files, Oracle, SQL
CS 4640
7
Separation of Concerns (2)
• doGet() and doPost() should be simple and short
• Shift processing to other methods and classes
• Put complicated logic in non-servlet classes
• Put almost no logic in JSPs
• JSPs should present data they get from other classes
DB
Use JSPs to present data that is on server
Use servlets to process user input
CS 4640
JSP
Servlet
Beans
and
Java classes
8
3.Tiered Architectures
J2EE Assumptions about data
• Data values: contents of memory
• Change very frequently (during execution)
• Data presentation: how the data is presented
• Change occasionally
• Data structure: types, organization and relationships of different
data elements
• Changes infrequently
CS 4640
9
Multi-Tiered Architectures
Each software layer only communicates with adjacent layers
JSPs & Servlets
Presentation layer
JSP Beans
Web-specific libraries
Business logic layer
Data layer
Data storage
CS 4640
Algorithms
Business Processing
Data Reading and Writing
DB, XML, Data files
Other software
Communicates
with users
Standard Java
Most software
is here
Separate
concerns
Enables
distribution
10
4. Page Centric and Dispatcher Designs
Page-centric (client-server)
• Requests are made to JSP pages, and the JSP pages response to
clients
Dispatcher (N-tier)
• Requests are sent to JSPs or servlets that then forward the
requests to another JSP or servlet
The goal is to separate logic from presentation and
to separate as many concerns in the logic as possible
CS 4640
11
Page-centric Design
Server
Web client
Web client
JSPs or servlets
(Client requests are
intercepted here)
Database
Uses or instantiates
Java Beans
Web client
CS 4640
12
Dispatcher Design
Server
Web client
Dispatcher
(JSP or servlet)
Database
Web client
CS 4640
Usually use forward
Web client
JSP
presentation
Beans
JSP
presentation
Beans
Business
processing
JSP
presentation
13
5. Model View Controller
• An abstraction frequently used in web app design
• Provide a way to divide the responsibilities of objects
• Decreases coupling between objects and layers (supports
easier maintenance)
• Help divide the work (supports development expertise areas)
CS 4640
14
5. Model View Controller (2)
Model
method calls
• Encapsulates application state
• Responds to state queries
• Exposes application functionality
• Notifies views of changes
events
state query
change
notification
View
• Renders the model
• Requests updates from the model
• Sends user inputs to controller
• Allows controller to select view
HTML /
JSP
view
select
user
input
data
structures
state change
Java
servlets
Controller
• Defines application behavior
• Maps user actions to model updates
• Selects a view for response
• One view for each function
* Graphic from Designing Enterprise Applications with the Java 2 Platform,
Enterprise Edition, Nicholas Kassem et al., October 2000
CS 4640
15
Summary
• Common mistakes
• No design and no comments
• Not enough collaboration – entire team needs to understand the design
• Using only parts of a design framework
• Must use meaningful names of packages, classes, methods, and
variables
• Requires and design must be created first and be available to all
team members
• Every team member should be able to explain the design
CS 4640
16