330 likes | 437 Views
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.
E N D
SOEN 343Software 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
A programming/design language mechanism. A packaging / scoping mechanism for names Names can refer to data, types, … Especially, a means of packaging data. Access points at interface Encapsulation
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.
Controller View Model-View-Controller (MVC) Model
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 Presentation Application
Web-based Enterprise Applications • The big picture …
Enterprise Applications: Layers Presentation Domain Data Source
List of Main Patterns To Be Studied Page Controller Template View Presentation Front Controller Transform View Domain Model Transaction Script Domain Active Record Row Data Gateway Data Mapper Data Source Table Data Gateway
EA: MVC Page Controller Template View Presentation Front Controller Transform View Domain Model Transaction Script Domain Active Record Row Data Gateway Data Mapper Data Source Table Data Gateway
EA: MVC Page Controller Template View Presentation Domain Domain Model Data Source
Page Controller (Greeting servlet) Template View (Greeting.jsp) Example: Greeting Greeting
Enterprise Application Patterns Page Controller Template View Presentation Front Controller Transform View Domain Model Transaction Script Domain Active Record Row Data Gateway Data Mapper Data Source Table Data Gateway
Data Source Patterns Page Controller Template View Presentation Front Controller Transform View Domain Model Transaction Script Domain Active Record Row Data Gateway Data Mapper Data Source Table Data Gateway
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 : int name grade
Table Data Gateway PersGradeTDG - PersGradeTDG() + find(name) : ResultSet + findInRange(fg,tg) : ResultSet + insert(name,grade) : void + update(name,grade) : void + delete(name) : void
Active Record (Row Data Gateway) PersGradeAR name : String grade : int PersGradeAR(name, g) find(name) … // like RDG // Can also have domain logic getRank()