33
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler http://www.cs.concordia.ca/~gregb/home/ soen343h-f06.html

SOEN 343 Software Design

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

Page 1: SOEN 343 Software Design

SOEN 343Software Design

Section H Fall 2006

Dr Greg Butlerhttp://www.cs.concordia.ca/~gregb/home/soen343h-f06.html

Page 2: SOEN 343 Software Design

Outline• Encapsulation, Information Hiding

• Servlets

• MVC– GRASP Controller principle (Larman 17.13)– Using servlets– In Fowler’s EAA

• Fowler’s data handling patterns

Page 3: SOEN 343 Software Design

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

Page 4: SOEN 343 Software Design

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?

Page 5: SOEN 343 Software Design

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?

Page 6: SOEN 343 Software Design

Information Hiding

• Information Hiding may or may not be supported a the programming language level.

Page 7: SOEN 343 Software Design

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).

Page 8: SOEN 343 Software Design

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!");

}}

Page 9: SOEN 343 Software Design

Java Server Page

• Servlet:– Embed HTML inside code.

• JSP– Embed code inside HTML.

Page 10: SOEN 343 Software Design

HelloWeb.jsp

<%@ page contentType="text/html; charset=iso-8859-1" language="java" ... %>

<html><body>Hello Web!</body></html>

Page 11: SOEN 343 Software Design

Hello.jsp

<%@ page contentType="text/html; charset=iso-8859-1" language="java" ... %>

<html><body>Hello <%= request.getParameter("name") %></body></html>

Page 12: SOEN 343 Software Design

Java Server Page

• Implemented as a (special kind of) servlet.

Page 13: SOEN 343 Software Design

Model-View-Controller (MVC)

Model

ViewController

Page 14: SOEN 343 Software Design

Model-Views

Page 15: SOEN 343 Software Design

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).

Page 16: SOEN 343 Software Design

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

Page 17: SOEN 343 Software Design

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

Page 18: SOEN 343 Software Design

Controller Illustration: Web-based EA

Page 19: SOEN 343 Software Design

Server :Tut06ControllerServlet

HTTP Get

doGet(req,resp)

g:Greeting

req:

setAttribute("Greeting",g)

forward(".../Greeting.jsp")

Greeting.jsp

getAttribute(...)

g

...

getGreeting()

Page 20: SOEN 343 Software Design

Web-based Enterprise Applications

• The big picture …

Page 21: SOEN 343 Software Design

Enterprise Applications: LayersDo

mai

nDa

ta S

ourc

ePr

esen

tatio

n

Page 22: SOEN 343 Software Design

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

Page 23: SOEN 343 Software Design

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

Page 24: SOEN 343 Software Design

Dom

ain

Data

Sou

rce

Domain Model

Template ViewPage Controller

Pres

enta

tion EA: MVC

Page 25: SOEN 343 Software Design

Example: Greeting

Greeting

Template View(Greeting.jsp)

Page Controller(Greeting servlet)

Page 26: SOEN 343 Software Design

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

Page 27: SOEN 343 Software Design

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

Page 28: SOEN 343 Software Design

Data Source Patterns

• Hide SQL.

• Provide an abstraction for – One data row.– A collection of data row(s).

Page 29: SOEN 343 Software Design

Example: Person-Grade Table

Table attributes:

• name : String

• grade : intname grade

Page 30: SOEN 343 Software Design

Table Data Gateway

PersGradeTDG

- PersGradeTDG()

+ find(name) : ResultSet

+ findInRange(fg,tg) : ResultSet

+ insert(name,grade) : void

+ update(name,grade) : void

+ delete(name) : void

Page 31: SOEN 343 Software Design

Table Data Gateway: Find Code

Page 32: SOEN 343 Software Design

Table Data Gateway: FindInRange

Page 33: SOEN 343 Software Design

Active Record (Row Data Gateway)

PersGradeARname : String

grade : int

PersGradeAR(name, g)

find(name)

… // like RDG

// Can also have domain logic

getRank()