Download - SOEN 6011 Software Engineering Processes
![Page 1: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/1.jpg)
SOEN 6011Software Engineering Processes
Section SS Fall 2007Dr Greg Butler
http://www.cs.concordia.ca/~gregb/home/soen6011-f2007.html
![Page 2: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/2.jpg)
Week 6• Servlets and JSP• Larman Controller Principle• Fowler Front Controller
– GoF Command pattern– Java reflection to instantiate Command
![Page 3: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/3.jpg)
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 4: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/4.jpg)
Servlet: HelloWebpublic class HelloWebServlet extends HttpServlet
{protected void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException {ServletOutputStream out = response.getOutputStream();out.println("Hello Web!");}
}
![Page 5: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/5.jpg)
Java Server Page
• Servlet:– Embed HTML inside code.
• JSP– Embed code inside HTML.
![Page 6: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/6.jpg)
HelloWeb.jsp
<%@ page contentType="text/html; charset=iso-8859-1" language="java" ... %>
<html><body>Hello Web!</body></html>
![Page 7: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/7.jpg)
Hello.jsp
<%@ page contentType="text/html; charset=iso-8859-1" language="java" ... %>
<html><body>Hello <%= request.getParameter("name") %></body></html>
![Page 8: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/8.jpg)
Java Server Page
• Implemented as a (special kind of) servlet.
![Page 9: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/9.jpg)
Controller Illustration: Web-based EA
![Page 10: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/10.jpg)
Server :Tut06ControllerServlet
HTTP Get
doGet(req,resp)
g:Greeting
req:
setAttribute("Greeting",g)
forward(".../Greeting.jsp")
Greeting.jsp
getAttribute(...)
g
...
getGreeting()
![Page 11: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/11.jpg)
PATTERN: Controller
• What object in the domain (or application coordination layer) receives requests for work from the UI layer?
???
Presentation
ApplicationLogic
Video Store
Record Rental
Video ID
...
...
...
... ...
Clerk
rent(videoID)
Now what happens?
![Page 12: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/12.jpg)
PATTERN: Controller (Larman 17.13)
Problem: What object in the domain (or application coordination layer) receives requests for work from the UI layer?
System operations (see SSD): major input events to the system
The controller is the first object beyond the UI layer that is responsible for receiving or handling a system operations message.
Note that UI objects delegate system operation request to a controller.
![Page 13: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/13.jpg)
PATTERN: Controller (Larman 17.13)
Solution: Assign the responsibility to a class representing one of the following choices:
• A façade controller, which represents1. the overall system2. A root object3. A device that the software is running within, or4. A major subsystem
• A use case or session controller which represents a use case scenario in which the system operation occurs
![Page 14: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/14.jpg)
Fig. 17.21
Which class of object should be responsible for receiving this system event message?
It is sometimes called the controller or coordinator. It does not normally do the work, but delegates it to other objects.
The controller is a kind of "facade" onto the domain layer from the interface layer.
actionPerformed( actionEvent )
: ???
: Cashier
:SaleJFrame
presses button
enterItem(itemID, qty)
UI Layer
Domain Layer
system operation message
![Page 15: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/15.jpg)
Dom
ain
Data
Sou
rce
Transaction Script Domain Model
Data Mapper
Row Data Gateway
Front Controller
Template View
Transform View
Page Controller
Pres
enta
tion
Active Record
Fowler’s EA Patterns
Table Module
Table Data Gateway
![Page 16: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/16.jpg)
Front ControllerFowler: A controller that handles all requests
for a web site.
The Front Controller consolidates all request handling by channeling requests through a single handler object. This object can carry out common behaviour which can be modified at runtime with decorators. This handler then dispatches to command objects for behaviour particular to a request.
![Page 17: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/17.jpg)
Front ControllerGoF design pattern: Command
Use a Command object to encapsulate the steps that are executed by a command.
Command::doIt() executes commandAllows Command::unDoIt() etc
GoF design pattern: DecoratorDecorator::m() adds additional behaviour, but delegates
to real Object::m() for real behaviourEg, logging command execution before/after executing
command
![Page 18: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/18.jpg)
Page vs Front Controller – Differences in URL Page Controllers for A1 • http:/stu.cs/343A1/ViewTaskList• http:/stu.cs/343A1/AddTask• http:/stu.cs/343A1/RemoveAllTasks• …
Front Controller for A1• Base URL: http:/stu.cs/343A1/frontController• …/frontController
?command=ViewTaskList• …/frontController
?command=AddTaskGrade&title=abc&…
![Page 19: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/19.jpg)
Front Controller
FrontServlet
# processRequest ( )- getCommand ( )- getCommandClass ( )
FrontCommand
+ init ( )+ processRequest ( )
AddStudent
+ processRequest ( )
Servlet
+ init ( )+ destroy ( )# processRequest ( )# doGet ( )# doPost ( )+ getServletInfo ( )+ forward ( )+ forwardAbsolute ( )+ getUrlBase ( )
# controller
0..1
Error
+ processRequest ( )
![Page 20: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/20.jpg)
Front Controller
![Page 21: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/21.jpg)
Front Controller: Sequence Diagram
![Page 22: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/22.jpg)
Front Controller: ProcessRequest
![Page 23: SOEN 6011 Software Engineering Processes](https://reader035.vdocument.in/reader035/viewer/2022062302/568167a9550346895ddcf6b9/html5/thumbnails/23.jpg)
Front Controller (cont’d)