Upload
myra-hurley
View
31
Download
0
Tags:
Embed Size (px)
DESCRIPTION
SOEN 343 Software Design. Section H Fall 2006 Dr Greg Butler http://www.cs.concordia.ca/~gregb/home/soen343h-f06.html. Outline. Encapsulation, Information Hiding Servlets MVC GRASP Controller principle (Larman 17.13) Using servlets In Fowler’s EAA Fowler’s data handling patterns. - PowerPoint PPT Presentation
Citation preview
SOEN 343Software Design
Section H Fall 2006
Dr Greg Butlerhttp://www.cs.concordia.ca/~gregb/home/soen343h-f06.html
Outline• Encapsulation, Information Hiding
• Servlets
• MVC– GRASP Controller principle (Larman 17.13)– Using servlets– In Fowler’s EAA
• Fowler’s data handling patterns
Encapsulation• A programming/design language
mechanism.
• A packaging / scoping mechanism for names– Names can refer to data, types, …– Especially, a means of packaging data.
Data
Access points at interface
Information Hiding
• Design principle by which a module is assigned a “secret”.
• A module’s secret is usually– A design decision.
• What type of design decisions might we want to hide from the clients of a module?
Information Hiding
• Often one hides, e.g.– Data representation.– Choice of algorithm.– Interface details / access mechanism of
external entity (e.g. database, hardware)– …
• Goal: particular design choice “invisible” to clients.
• Why would we want to do this?
Information Hiding
• Information Hiding may or may not be supported a the programming language level.
Servlets, The General Idea
• Applet as a client side Java application.• Servlet as a server side technology for
implementing part of the functionality of an application.
• HTTP (URL) requests cause a servlet to be:– Instantiated (if it did not exist).– Run.– The servlet builds a response which is then sent back
to the client (usually in the form of HTML).
Servlet: HelloWeb
public class HelloWebServlet extends HttpServlet
{protected void doGet(
HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
{ServletOutputStream out
= response.getOutputStream();out.println("Hello Web!");
}}
Java Server Page
• Servlet:– Embed HTML inside code.
• JSP– Embed code inside HTML.
HelloWeb.jsp
<%@ page contentType="text/html; charset=iso-8859-1" language="java" ... %>
<html><body>Hello Web!</body></html>
Hello.jsp
<%@ page contentType="text/html; charset=iso-8859-1" language="java" ... %>
<html><body>Hello <%= request.getParameter("name") %></body></html>
Java Server Page
• Implemented as a (special kind of) servlet.
Model-View-Controller (MVC)
Model
ViewController
Model-Views
GRASP: Controller
• Who handles a system event?– E.g. “List Movies”
• Main choices: assign to a design entity representing– Overall system,
or subsystem (façade controller).– A Use Case scenario
(often named, e.g. ListMovieHandler).
GRASP: Controller Illustration
actionPerformed( actionEvent )
:Register
: Cashier
:SaleJFrame
presses button
1: enterItem(itemID, qty)
:Sale1.1: makeLineItem(itemID, qty)
Interface Layer
Domain Layer
system event message
controller
GRASP: Controller Illustration
actionPerformed( actionEvent )
:Register
: Cashier
:SaleJFrame
presses button
1: enterItem(itemID, qty)
:Sale1.1: makeLineItem(itemID, qty)
Interface Layer
Domain Layer
system event message
controller
Presentation
Application
Controller Illustration: Web-based EA
Server :Tut06ControllerServlet
HTTP Get
doGet(req,resp)
g:Greeting
req:
setAttribute("Greeting",g)
forward(".../Greeting.jsp")
Greeting.jsp
getAttribute(...)
g
...
getGreeting()
Web-based Enterprise Applications
• The big picture …
Enterprise Applications: LayersDo
mai
nDa
ta S
ourc
ePr
esen
tatio
n
Dom
ain
Data
Sou
rce
Table Data Gateway
Transaction Script Domain Model
Data MapperRow Data Gateway
Front Controller
Template View
Transform View
Page Controller
Pres
enta
tion
Active Record
List of Main Patterns To Be Studied
Dom
ain
Data
Sou
rce
Table Data Gateway
Transaction Script Domain Model
Data MapperRow Data Gateway
Active Record
Front Controller
Template View
Transform View
Page Controller
Pres
enta
tion EA: MVC
Dom
ain
Data
Sou
rce
Domain Model
Template ViewPage Controller
Pres
enta
tion EA: MVC
Example: Greeting
Greeting
Template View(Greeting.jsp)
Page Controller(Greeting servlet)
Dom
ain
Data
Sou
rce
Table Data Gateway
Transaction Script Domain Model
Data MapperRow Data Gateway
Front Controller
Template View
Transform View
Page Controller
Pres
enta
tion
Active Record
Enterprise Application Patterns
Dom
ain
Data
Sou
rce
Table Data Gateway
Transaction Script Domain Model
Data MapperRow Data Gateway
Active Record
Front Controller
Template View
Transform View
Page Controller
Pres
enta
tion Data Source Patterns
Data Source Patterns
• Hide SQL.
• Provide an abstraction for – One data row.– A collection of data row(s).
Example: Person-Grade Table
Table attributes:
• name : String
• grade : intname grade
Table Data Gateway
PersGradeTDG
- PersGradeTDG()
+ find(name) : ResultSet
+ findInRange(fg,tg) : ResultSet
+ insert(name,grade) : void
+ update(name,grade) : void
+ delete(name) : void
Table Data Gateway: Find Code
Table Data Gateway: FindInRange
Active Record (Row Data Gateway)
PersGradeARname : String
grade : int
PersGradeAR(name, g)
find(name)
… // like RDG
// Can also have domain logic
getRank()